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
Intraclass correlations with meologit?Hi all, I'm revisiting my analysis for a revise & resubmit article but I'm having trouble repli…
Export data in histogramI am new to stata (I am using version Stata/IC 12.1 for Mac, 64-bit Intel) and succeeded in producin…
analysis on two-eye datasetHello, I am trying to compare the intraocular pressure (IOP, a continuous variable) between two trea…
How to introduce initial values in CMP for 4 eq. TobitsHi, I am estimating a model with 4 equations, each of them Tobit for a Time Use Survey (US edition).…
Cox model margins estimatesDear colleagues, I am using STATA version 15.1 and am struggling to estimate margins for a continuo…
Subscribe to:
Post Comments (Atom)
0 Response to Converting string variable into month, quarter and year
Post a Comment