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]

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


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: matcell option in tab command within a loop inside postfile
Date   Sat, 23 Feb 2013 09:57:39 +0000

The number of categories is stored in r(r) after -tabulate, so even
with that approach you need do nothing with matrices.

However, none of this is needed. -distinct- (SJ) gives you this output
directly. -search distinct- to get a location from which to download.

I haven't tried finding what is wrong with your code, given other ways
to do it.

The correct spelling is "Stata". Please do read the FAQ carefully
before posting, as requested.

Nick

On Sat, Feb 23, 2013 at 4:31 AM, Jenny Yu <[email protected]> wrote:

> 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?
*
*   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