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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: foreach loop


From   Lisa Wang <lhwang0925@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: foreach loop
Date   Sun, 5 Aug 2012 12:03:46 +1000

Hi all,

Can someone please teach me as to why this is invalid:

local x 1 2 3 4
foreach x in 1/4 {
codebook a* if m_marks==`x'			
tab a* if m_marks==`x'	
}

I have been learning Stata for only a month, so any suggestions would
be greatly appreciated. Or how to do it more elegantly would be great
as well.

I have 4 categories for m_marks only and I wanted to use a local to
loop over the codebook and tab functions for each category, instead of
typing it out 4 times.

Thank you,
Lisa
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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