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

Re: st: filling previous missing observations repeatedly.


From   Shourun Guo <[email protected]>
To   [email protected]
Subject   Re: st: filling previous missing observations repeatedly.
Date   Mon, 12 Jul 2004 11:46:24 -0400

Maybe you can firstly "sort -year" . It means sort year decendingly and thaen run the replace statement. But you need to pay attention to the observation index.


 |  On Mon, 12 Jul 2004 16:19:31 +0100
 |  "Dev Vencappa" <[email protected]> wrote:
 |  >>
 |  >>
 |  >>
 |  Stata users, I have the following data set
 |  
 |  year           B           C          Country
 |  1995          .            x           Belgium
 |  1996          .            x           Belgium
 |  1997          .            x           Belgium
 |  1998          .            x           Belgium
 |  1999          x           x           Belgium
 |  2000          .            x           Belgium
 |  2001          .            x           Belgium
 |  2002          .            x           Belgium
 |  
 |  Variable B has data for only 1999 and missing for other years. I want to extrapolate missing years using variable C, which is some kind of multiplicative scalar that varies over the years. Writing a command like the following seems to work fine to fill missing values after year 1999:
 |  
 |  replace B=B[_n-1]*C if B==. & year>1999 & country=="Belgium"
 |  
 |  However, the following does not seem to work (or at least fills the missing value for the year 1998 only):
 |   
 |  replace B=B[_n+1]*C if B==. & year<1999
 |  
 |  I believe this is because Stata works only forward and not backward. Is there a way to ask Stata to work backwards starting with the value from the year 1999 and repeat the command for prior years? I have tried the following loop command but that does not seem to work either (this command does not even fill in the missing value for the year 1998, for obvious reasons)
 |  
 |  while B[_n+1]!=. & B==. & country=="Belgium"{
 |  replace B=B[_n+1]*C
 |  }
 |  
 |  I think I am missing a syntax of Stata here.
 |  
 |  Many thanks
 |  Dev
 |  
 |  
 |  
 |  
 |  This message has been scanned but we cannot guarantee that it and any
 |  attachments are free from viruses or other damaging content: you are
 |  advised to perform your own checks.  Email communications with the
 |  University of Nottingham may be monitored as permitted by UK legislation.
 |  
 |  
 |  *
 |  *   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/

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