Hi, I am fairly new to stata and am having difficulty creating a string variable identifying year and quarter eg. 2012Q1, in order to merge two data sets together.
Currently I have gotten as far as getting the month and year as variables using:
gen month1 = substr(date, 3, 3)
gen year1 = substr(date, 6, 4)
destring year1, replace
replace month3 = 1 if month1 == "jan"
replace month3 = 2 if month1 == "feb"
replace month3 = 3 if month1 == "mar"
replace month3 = 4 if month1 == "apr"
replace month3 = 5 if month1 == "may"
replace month3 = 6 if month1 == "jun"
replace month3 = 7 if month1 == "jul"
replace month3 = 8 if month1 == "aug"
replace month3 = 9 if month1 == "sep"
replace month3 = 10 if month1 == "oct"
replace month3 = 11 if month1 == "nov"
replace month3 = 12 if month1 == "dec"
I now need to create a quarter variable as a string eg Q1 for month3 = 1 | 2 | 3... and then combine this with the year to create a variable matching the one in the other data set so as to merge. The switching between string and numeric is causing some difficulties and I am not sure where to go from here
thanks in advance for any advice
Currently I have gotten as far as getting the month and year as variables using:
gen month1 = substr(date, 3, 3)
gen year1 = substr(date, 6, 4)
destring year1, replace
replace month3 = 1 if month1 == "jan"
replace month3 = 2 if month1 == "feb"
replace month3 = 3 if month1 == "mar"
replace month3 = 4 if month1 == "apr"
replace month3 = 5 if month1 == "may"
replace month3 = 6 if month1 == "jun"
replace month3 = 7 if month1 == "jul"
replace month3 = 8 if month1 == "aug"
replace month3 = 9 if month1 == "sep"
replace month3 = 10 if month1 == "oct"
replace month3 = 11 if month1 == "nov"
replace month3 = 12 if month1 == "dec"
I now need to create a quarter variable as a string eg Q1 for month3 = 1 | 2 | 3... and then combine this with the year to create a variable matching the one in the other data set so as to merge. The switching between string and numeric is causing some difficulties and I am not sure where to go from here
thanks in advance for any advice
Comment