Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: matcell option in tab command within a loop inside postfile


From   "Jenny Yu" <[email protected]>
To   <[email protected]>
Subject   st: matcell option in tab command within a loop inside postfile
Date   Sat, 23 Feb 2013 00:31:37 -0400

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index