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

Re: st: filling previous missing observations repeatedly.


From   Nick Winter <[email protected]>
To   [email protected]
Subject   Re: st: filling previous missing observations repeatedly.
Date   Mon, 12 Jul 2004 12:42:41 -0400

Assuming you have multiple countries and years, the ultimate solution here probably also uses the -by- prefix, to do all the countries and years in one fell swoop. Something like:

. bysort country year: replace B=B[_n-1]*C if B==.
. gen nyear = -year
. bysort country nyear: replace B=B[_n-1]/C if B==.
. drop nyear


--Nick Winter
At 05:24 PM 7/12/2004 +0100, you wrote:

>>
>>
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
>
--------------------------------------------------------
Nicholas Winter 607.255.8819 t
Assistant Professor 607.255.4530 f
Department of Government [email protected] e
308 White Hall falcon.arts.cornell.edu/nw53 w
Cornell University
Ithaca, NY 14853-4601

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