问题
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