Bookmark and Share

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]

st: Keep variables if a value is available for a specific date


From   Tanja Berg <[email protected]>
To   [email protected]
Subject   st: Keep variables if a value is available for a specific date
Date   Mon, 14 May 2012 09:33:32 +0200

Thanks, Nick.

I think I can't do it that way, because the correct date is essential to my further work. I want to do an IRR calculation afterwards.
So if the price for e.g. the 31.03. is missing and the next available price is for the 01.04. I need the price for that day AND the correct date, the 01.04. If I would copy the price from 01.04. upwards to the 31.03. my IRR calculation will mess up.

Is there a solution for this problem?

Best regards
Tanja
-------------------


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/

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index