Statalist


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

st: R: re: a question related to -foreach-


From   "Carlo Lazzaro" <[email protected]>
To   <[email protected]>
Subject   st: R: re: a question related to -foreach-
Date   Tue, 21 Oct 2008 18:37:31 +0200

Dear Kit,
thanks a lot for your kind and helpful reply.

I am anxiously longing to take a look at your fortcoming textbook for
imporoving my (poor) Stata programming skills!

Thanks a lot agin and Kind Regards,

Carlo

-----Messaggio originale-----
Da: [email protected]
[mailto:[email protected]] Per conto di Christopher Baum
Inviato: martedì 21 ottobre 2008 18.20
A: [email protected]
Oggetto: st: re: a question related to -foreach-

< >
Carlo asks
. foreach x of varlist b1-b36 {
  2. summarize `x'
3. }
  I would like to generate a newvar in which the r(mean) for each one  
of the 36 variables included in varlist are stored. How can I do this  
in Stata 9.2/SE?

No need to use a foreach loop.

tabstat b1-b36, save
mat mu = r(StatTotal)'
mat li mu

If for some reason you want these in a variable, use -svmat-:

svmat mu

which creates variable mu1, obs. 1-36.


Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html

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



*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index