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: re: variable estimation


From   Christopher Baum <[email protected]>
To   <[email protected]>
Subject   st: re: variable estimation
Date   Sun, 7 Nov 2010 19:11:24 -0500

<>
> *get number of groups per t
> bysort igroup : g trun =_n 
> local nGroups =r(n) 
> 
> *get mean return per t = r_m,t
> g r_m = (sum(return))/_n
> 
> *get csad
> g csad = (abs(return - r_m))/`nGroups'

As Nick Cox said, this is a job for -egen-. Note that the use of the generate sum() function above does not do what you think. It is a running sum. If you want a mean, egen mean() will do the job.

Kit

Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
                              An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.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/


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