2017-04-05 13 views
0

私は教育統計のための国立センターからIPEDSと呼ばれる教育データセットを使って作業しています。大学では、専攻、学位修了などに基づいて学生を追跡します。Stataの問題は、特定の専攻科目によって得られた学位の合計数を決定しようとしていることです。精度と数

「メジャー」として機能する値を含む変数cipcodeを持っています。私は

tab cipcode if cipcode==14.2501 

のような特定のコードを書くときcipcodeは等々14.2501「石油工学、16.0102 『言語学』とあるかもしれない。

それはno observationsを報告します。私の合計を与えるだろう何のコード?

/*Convert Float Variable to String Variable and use Force Replace*/ 
tostring cipcode, gen(cipcode_str) format(%6.4f) force 
replace cipcode_str = reverse(substr(reverse(cipcode_str), indexnot(reverse(cipcode_str), "0"), .)) 
replace cipcode_str = reverse(substr(reverse(cipcode_str), indexnot(reverse(cipcode_str), "."), .)) 

/* Created a total variable called total_t1 for total count of all stem majors listed in table 1*/ 
gen total_t1 = cipcode_str== "14.2501" + "14.3901" + "15.0999" + "40.0601" 
+0

スペルはStataです:編集時に修正されました。 –

答えて

0

この最小限の例では、あなたの問題を確認した。(ちなみに、良い例のアドバイスをhttps://stackoverflow.com/help/mcveを参照してください。)

* code 
clear 
input code 
14.2501 
14.2501 
14.2501 
end 

tab code if code == 14.2501 
tab code if code == float(14.2501) 

* results 
. tab code if code == 14.2501 
no observations 

. tab code if code == float(14.2501) 

     code |  Freq.  Percent  Cum. 
------------+----------------------------------- 
    14.2501 |   3  100.00  100.00 
------------+----------------------------------- 
     Total |   3  100.00 

キーワードは、精度を使用するキーワードです。 Stataでは、リソースはsearch precision、William Gouldのブログ記事から始まります。 14.2501のような小数は、正確にバイナリで保持するのは難しい(不可能)ので、型を変数として保持することの詳細はfloatが噛むことができます。

説明していない最後のコードブロックで何をしているのか分かりません。最後のステートメントは、文字列を追加するときに困惑しています。結果が有効cipcodeすることはできません長い文字列である

. gen whatever = "14.2501" + "14.3901" + "15.0999" + "40.0601" 

. di whatever[1] 
14.250114.390115.099940.0601 

で何が起こるかを考えてみましょう。

... if inlist(cipcode_str, "14.2501", "14.3901", "15.0999", "40.0601") 

に達していると思われます。

しかし、float()を使用することは、この問題の最小限のトリックです。