Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[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" <>
To   <>
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,

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index