Can't eliminate rows with na. Stata says ambiguous abbreviation

半世苍凉 提交于 2019-12-12 03:06:49

问题


In the dta file, there is this column

ColumnA
 1
 2
 1
 na
 .
 .

so I want to eliminate na and .

But when I do

drop if ColumnA==na

then Stata says (in red)

na ambiguous abbreviation

What is this? How can I successfully eliminate rows with "na" ?


回答1:


This means that you have two (or more) variables that begin with the stub na. Stata interprets what you typed as drop the observation if the value of ColumnA is equal to value of variable na. Since Stata does not know which na variable you mean, it errors.

You should use either of these if ColumnA is a string variable:

drop if ColumnA == "na" | ColumnA == "." 
drop if inlist(ColumnA,"na",".")

If instead ColumnA is a numeric variable with integer values that has a value label attached, you need to specify the label name like this:

drop if ColumnA == "na":ColumnA_Value_Label

You can get the value label name with

describe ColumnA 


来源:https://stackoverflow.com/questions/38112449/cant-eliminate-rows-with-na-stata-says-ambiguous-abbreviation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!