Dear all,

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
I understand that there are probably less complicated ways of achieving this. The code seems to work and the current_month variable shows 1975m1 for cumulative month, however, when I try to extract the month and year from the variable, I get dates for the year 1960 and 1961. What am I doing wrong? Any help will be highly appreciated.

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
Sincerely,

Chiara