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.
Related Posts with Converting string variable into month, quarter and year
How do I get time difference (gap) in second?I have a dataset like this Code: * Example generated by -dataex-. To install: ssc install dataex cl…
PPML extraction of standard errors matrix of fixed effectsDear @Joao Santos Silva As PPML produces robust standard errors, I am wondering how I can extract t…
Help!!! Convergence error in calculating of productivity by SFA - "Kumbhakar, S.C, 2015"Hi everyone, I am calculating total factor productivity by the SFA model in using STATA. When I ru…
Estimating Okun's Law using data from Economic Report of the President 2020Hi, I am a beginner in stata, trying to estimate Okun's law using data from Economic Report of the …
How to Reduce Rows by Collapsing Repeating DatesI'm trying to create an appropriate time series from the below data. The dates repeat because of the…
Subscribe to:
Post Comments (Atom)
0 Response to Converting string variable into month, quarter and year
Post a Comment