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
Instrumental variables with many missing values in the endogenous regressorHi, I have a data set with 10k observations for Y and an endogenous regressor X with many missing o…
Dummy variable interpretation Code: Source | SS df MS Number of obs = 1,315 -------------+…
Help with regression of (unbalanced) panel data - xtreg, statsby/regressby generating difference resultsHi Statalist! First of all, thank you for all the help you give on a daily basis! It's been very he…
Logistic Regression with ClusteringHello users, I am new to the forum, but hoped you would be able to settle a small dispute we are ha…
gmm estimation of probit model in the presence of heteroscedasticityDear statalists, I tried to conduct a Monte Carlo simulation to show that under conditional heteros…
Subscribe to:
Post Comments (Atom)
0 Response to Converting string variable into month, quarter and year
Post a Comment