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:11:47 +0100

>>>
>>>>
 Scott, Nick

 thanks for your help. I believe I was not very explicit in my email. Nick's solution works fine but it takes the same value for B in 1999 and multiplies it by C for previous years. What I should have mentioned in my email is that I want the new value of B created for each of the years before and after 1999 to be multiplied by C. 
  Scott, your solution works but only for the year 1998. I have tried gsort -year and that is doing the job.

Many thanks

Dev

>>> [email protected] 07/12/04 05:00pm >>>
How about this:


while b == . {
	replace b=b[_n+1]*c if b==. & year <1999
	replace b=b[_n-1]*c if b==. & year >1999
}


Scott


----- Original Message -----
From: Dev Vencappa <[email protected]>
Date: Monday, July 12, 2004 10:19 am
Subject: Re: st: filling previous missing observations repeatedly.

> >>
> >>
> >>
> 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


*
*   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