Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | magic_n2a@gmx.de |
To | statalist@hsphsun2.harvard.edu |
Subject | st: Fwd: replace values given specific dates |
Date | Fri, 14 Sep 2012 21:54:35 +0200 |
Hello again, I have worked out following and it takes (now) 4 days and it is still replacing values. Can someone help??? I am just soooooooo... confused. Thank you very much!!! Kind regards Natali Worked out: egen bomdL3=bomd(date), lag(3) work f(%td) egen eomdL3=eomd(date), lag(3) work f(%td) gen pbomdL3=. gen peomdL3=. gen J3=. qui levelsof eomdL3, local(eomdL3) qui levelsof bomdL3, local(bomdL3) foreach i of local id { foreach d of local bomdL3 { qui summarize price if id==`i' & date==`d', meanonly qui local p=r(mean) qui replace pbomdL3=`p' if id==`i' & bomdL3==`d' } } -------- Original-Nachricht -------- Datum: Fri, 07 Sep 2012 21:13:44 +0200 Von: magic_n2a@gmx.de An: statalist@hsphsun2.harvard.edu Betreff: replace values given specific dates Dear Statalist-User, I have a problem that I am not able to solve. My data looks like this (panal data from 01.06.2001 - 01.06.2012): 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/