I tried coding (see below) to generate a new date variable in month from a large panel data with ticker and a date variable that gives the star and end date for each firm. Below I show a few observations.
Code:
clear input str6 ticker long statpers "TLMR" 20140417 "TLMR" 20140515 "TLMR" 20140619 "TLMR" 20140717 "TLMR" 20140814 "TLMR" 20140918 "TLMR" 20141016 "TLMR" 20141120 end
I want to add a month variable for each observation, 201404, 201405, …. 201411 , 8 months for this ticker. What I tried (my coding is inefficient).
Code:
sort ticker statpers by ticker: gen s_date=statpers if _n==1 by ticker: gen e_date=statpers if _n==_N bysort ticker: carryforward s_date, gen(s_fill) gsort ticker - e_date bysort ticker: carryforward e_date, gen(e_fill)
Thank you,
Rochelle
0 Response to Generate a new date variable from a panel data
Post a Comment