我正在使用一套 dta
代表不同年份调查的文件。
方便的是,每年为 country
使用不同的值。变量,所以我试图设置 country
要匹配的每年的值标签。不过,我在比较值标签时遇到了麻烦。
到目前为止,我想出了以下代码:
replace country=1 if countryO=="Japan"
replace country=2 if countryO=="South Korea" | countryO=="Korea"
replace country=3 if countryO=="China"
replace country=4 if countryO=="Malaysia"
但是,这不起作用,因为“日本”是值标签,而不是实际值。
我如何告诉 Stata 我正在比较值标签?
最佳答案
尝试
replace country=1 if countryO=="Japan":country0valuelabel
replace country=2 if inlist(countryO,"South Korea":country0valuelabel,"Korea":country0valuelabel)
您将不得不更换
country0valuelabel
在您的数据中使用相应的值标签名称。您可以通过查看 describe country0
输出中的倒数第二列来找出它的名称。 .
关于stata - 在 if 命令中使用值标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22767838/