Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: elementary panel data management question


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: elementary panel data management question
Date   Fri, 22 Apr 2005 16:09:06 +0100

This is not quite what was asked. 

Scott is flagging here that missing values 
of -invest- are problematic, but with 
this code fewer than 5 values will 
be identified whenever -invest- is missing. 

My posting indicates another way.

Nick 
n.j.cox@durham.ac.uk 

Scott Merryman
 
> Here is one way, using the "grunfeld.dta" data set with 
> investment as the
> variable of interest:
> 
> . webuse grunfeld
> 
> . sort year invest
> 
> . gen top5 = .
> (200 missing values generated)
> 
> . by year: replace top5 = 1 if _n  >_N-5 & invest <.
> (100 real changes made)
> 
> . replace top = 0 if top ==.
> (100 real changes made)
> 
> . egen total = sum(invest) if top == 1 , by(year)
> (100 missing values generated)

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index