Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Keep variables if a value is available for a specific date
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Keep variables if a value is available for a specific date
Date
Sun, 13 May 2012 19:18:52 +0100
This is a three-stage operation. First, create a flag for missing data
so that you can keep track of what you filled in.
gen ismissing(price)
Second, fill in missing prices with the next available price using the
procedure described at
FAQ . . . . . . . . . . . . . . . . . . . . . . . Replacing missing values
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
2/03 How can I replace missing values with previous or
following nonmissing values?
http://www.stata.com/support/faqs/data/missing.html
Third, keep only the dates of interest.
Nick
On Sun, May 13, 2012 at 4:44 PM, Tanja Berg <[email protected]> wrote:
> My data set looks like the following:
>
> ID Date Price
> 1 01.01.2005 100
> 1 02.01.2005 100,9
> 1 03.01.2005 100,5
> 1 04.01.2005 100,3
> ... .... ....
> 2 01.01.2005 100
> 2 02.01.2005 100,3
> 2 03.01.2005 a. (missing)
> 2 04.01.2005 100,4
> ... .... ....
>
>
> For each ID I only want to keep the observations for the 31.03., 30.06., 30.09. and 31.12. of each year in my dataset. But if e.g. the price on the 31.03. is missing I want to keep the next possible available price.
> My dataset is so large I can't look at each observation separately. So I think I will need some kind of loop that checks if the price e.g. for the 31.03. is available and then keeps the observation or if the price is not available, checks the 01.04. if there is a price available and then keeps this observation etc.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/