Hello,
Can you help me with the following issues:
I have a dataset with a variable called "date" that has monthy values for several years by country (the dataset has 71 countries). The aforementioned "date" is a string variable in the following format: 1984_m1, 1984_m2,...1984_m12 (per country).
I would like to create three variables: one variable only for values of the month, other with the mean values of the corresponding quarter and other with the mean values of the corresponding year. I will call then: "month", "quarter" and "year". I would like it to appear for the "month" the corresponding number of the month: 1 2 3 4 5...12; and for the "quarter" the corresponding numbers of the quarter: 1 2 3 4
I tried to use the following command but they are not working as I want:
gen date1=monthly(date,"YM")
gen date2 = dofm(date1)
format date2 %d
(until this step the result of the convertion of "1984_m1" is something like "01jan1984"..in this case I would like it to appear the last day of the month: something like "31jan1984")
(the other steps don´t give me the desired results):
gen month=month(date2)
gen yr=year(date2)
gen quarter=quarter(date2)
Can you help me with the necessary commands to achieve the results that I want?
Thank you in advance.
0 Response to Converting string variable into month, quarter and year
Post a Comment