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]

AW: st: how to save summarize data


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: how to save summarize data
Date   Sat, 19 Jun 2010 18:46:32 +0200

<> 

There is no need to speculate on the number of levels in a variable you want
to loop over, you can simply -levelsof- the thing (see NJC`s
http://www.stata.com/support/faqs/data/foreach.html):


*************
sysuse auto, clear
gen myloopmean=.
qui levelsof rep78
foreach lev in `r(levels)'{
su mpg if rep78 ==`lev', mean
replace myloopmean=r(mean) if rep78 ==`lev'
}
bys rep78: egen myegenmean=mean(mpg)
l rep78 myloopmean myegenmean, sepby(rep78) h(20)
*************

Note that the -egen- approach advocated in my earlier posting deals
elegantly and automatically with missings, while the loop solution does
not...


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Sabrina
Carrossa
Gesendet: Samstag, 19. Juni 2010 18:01
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: how to save summarize data

I am not sure that the following is the best solution, but it works.
Let's suppose that the variable "companies" is a numeric one (i.e.
from 1 to 10).

gen EFNmean=.
forevalues c= 1/10 {
              summarize EFN if companies==`c'
              replace EFNmean=r(mean) if companies==`c'
}


sabry



On 19 June 2010 17:21, Thomas Gericks <ThomasGericks@web.de> wrote:
> Hello,
>
> I am working with panel data. I am analyzing several companies over a time
period.
>
> I generated a variable indicating the capital structure (EFN) of the
company for every year.
> Now I want to have the mean per company over the time period.
>
> I know how to get it but i want to save the mean as a new variable.
>
> A way to read it is:
>
> bys company, summarize EFN
>
> how can i now save it as a variable for every company?
>
>
> Thanks a lot for your help,
>
> Thomas Gericks
>
>
> ___________________________________________________________
> WEB.DE DSL ab 19,99 Euro/Monat. Bis zu 150,- Euro Startguthaben und
> 50,- Euro Geldprämie inklusive! https://freundschaftswerbung.web.de
>
> *
> *   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/
>



-- 
sabrina

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index