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: replace values given specific dates


From   [email protected]
To   [email protected]
Subject   st: replace values given specific dates
Date   Fri, 07 Sep 2012 21:13:44 +0200

Dear Statalist-User,

I have a problem that I am not able to solve.
My data looks like this (panal data):

bomdL3       eomdL3      J3   dow   date        id    price
01mar2006    31mar2006    .    1    26jun2006    1    10.988
01mar2006    31mar2006    .    2    27jun2006    1    11.237
01mar2006    31mar2006    .    3    28jun2006    1    11.336
01mar2006    31mar2006    .    4    29jun2006    1    11.336
01mar2006    31mar2006    .    5    30jun2006    1    11.336
------------
03apr2006    28apr2006    .    1    03jul2006    1    11.714
03apr2006    28apr2006    .    2    04jul2006    1    11.714
03apr2006    28apr2006    .    3    05jul2006    1    11.336
03apr2006    28apr2006    .    4    06jul2006    1    10.939
03apr2006    28apr2006    .    5    07jul2006    1    11.436
------------
03apr2006    28apr2006    .    1    10jul2006    1    11.436
03apr2006    28apr2006    .    2    11jul2006    1    11.436
03apr2006    28apr2006    .    3    12jul2006    1    11.436
03apr2006    28apr2006    .    4    13jul2006    1    11.436
03apr2006    28apr2006    .    5    14jul2006    1    10.74
                                                 2
                                                 3
                                                 5
                                                ...
                                                552 (some ID's are missing)

I would like to readout the date in _n==1 (i.e. 01mar2006) for the variable bomdL3 (date at the beginning of each month with lag 3).
Then, I want to search for the price that each id (company) had on that given date.
Finally, I want to have this price inserted in J3.

I would like to calculate a performance for each id for the period of the last 3 month (for example).

I have used the following code, but it takes days to calculate it this way for my dataset:

generate J3=.
local N=_N
forvalues j=1/552     {
forvalues i=1/`N'     {
    qui sum eomdL3 if _n==`i'
    qui sum price if id==`j' & date==r(max)
    qui replace J3=r(max) in `i'
            }
            }

I have read a lot of threads and literature and can't get a program code for my panel data that works well.
Is there anyone how could help me?
Thank you very much!
Best regard,
Natali
*
*   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