Why does Stata complain with a cryptic error when I use string variables in the table
command?
Consider the following toy example:
sysuse auto, clear
decode foreign, g(foreign_str)
table foreign, contents(n foreign_str mean mpg)
This raises an r(111) variable __000002 not found
error in Stata 13.1.
Tracing the error tells me that it is trying to run format __000002 %9.0gc
and crashing when it does not find the variable. If I switch the order of the variables in the clist
, that is i run table foreign, contents(n mpg_rank mean mpg)
, I get the same error but with __000003
instead of __000002
.
So it appears that Stata crashes when it finds the string variable. If I replace the string variable with a numeric variable, the error doesn't occur.
I know it is not meaningful to compute summary statistics on string variables, but counting the number of observations of a string variable (in each group specified by the rowvar) makes perfect sense.
table foreign, contents(freq mean mpg)
to get around this. – dimitriy