Dear all,
I have the following STATA code for extracting the maximum number of the
categories for each variable in my varlist:
use "h:\mydata.dta", clear
tempname memhold
postfile `memhold' str20 yvar maxm1 using temp, replace
foreach yvar of varlist * {
capture tab `yvar', matcell(m)
svmat m
egen maxm1=max(m1)
post `memhold' ("`yvar'") (maxm1)
drop m1 maxm1
}
postclose `memhold'
If I open stata and run this do file. It does not run and error message
is: "matrix m not found" "r(111);"
However, after this error warning, if I type(notes: var1 is any of the
variables in my varlist):
tab var1, matcell(m)
svmat m
Not only these two lines are fine, but also this time, the above whole
postfile works perfectly. But as soon as I close stata and open stata
again, run the do file, everything above repeats.
Does anyone know why I have to use "tab var1, matcell(m); svmat m;"
first, and then the whole postfile works just fine? Or there are some
other tricks here?
Thanks in advance,
Jenny
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/