I have a panel data with a large number of groups and the cumulative number of months (1 - 372) for January 1995 to December 2005. My goal is to extract the corresponding month and year for each observation.
I used the following code;
Code:
gen startdate = "1975-01-01" gen enddate = "2005-12-31" gen start = date(startdate, "YMD") gen ep_end = date(enddate, "YMD") format start ep_end %td gen start_m = mofd(start) gen ep_end_m = mofd(ep_end) format start_m ep_end_m %tm gen index = month - 1 gen current_month = start_m + index format current_month %tm
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(id month) str10 startdate str11 enddate str6 start_m str7 ep_end_m 1 1 "1-Jan-1975" "31-Dec-2005" "1975m1" "2005m12" 1 2 "1-Jan-1975" "31-Dec-2005" "1975m1" "2005m12" 1 3 "1-Jan-1975" "31-Dec-2005" "1975m1" "2005m12" 2 1 "1-Jan-1975" "31-Dec-2005" "1975m1" "2005m12" 2 2 "1-Jan-1975" "31-Dec-2005" "1975m1" "2005m12" 2 3 "1-Jan-1975" "31-Dec-2005" "1975m1" "2005m12" 3 1 "1-Jan-1975" "31-Dec-2005" "1975m1" "2005m12" 3 2 "1-Jan-1975" "31-Dec-2005" "1975m1" "2005m12" 3 3 "1-Jan-1975" "31-Dec-2005" "1975m1" "2005m12" end
Chiara
0 Response to Year and month from cumulative number of months by group
Post a Comment