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

Re: st: filling previous missing observations repeatedly.


From   "Dev Vencappa" <[email protected]>
To   <[email protected]>
Subject   Re: st: filling previous missing observations repeatedly.
Date   Mon, 12 Jul 2004 17:24:32 +0100

>>
>>
Thanks a lot for your solution. In fact, this is exactly what I did and it is working fine.

Dev
>>> [email protected] 07/12/04 04:59pm >>>
Why not try using what you had for the observations after 1999, then a 
reverse sort and a similar command for prior to 1999.

eg:
. replace B=B[_n-1]*C if B==. & year>1999 & country=="Belgium"
. gsort country -year
. replace B=B[_n-1]/C if B==. & year<1999 & country=="Belgium"


Dev Vencappa 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/ 
>  
>


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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index