Hi, Statalists
I have a problem dealing with a string date variable which is with annual and quarterly data at the same time, as the data following.
I wish I can convert the string date variable which is quarterly and annually into a date variable
So far, I have attempted using yearly() and quarterly() commands; however, they didn't work as I expected.
And the code below is currently in my procedure.
And I expect the data would be like the data below
Appreciate your reading and expect your response
Enzo
I have a problem dealing with a string date variable which is with annual and quarterly data at the same time, as the data following.
I wish I can convert the string date variable which is quarterly and annually into a date variable
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str3 countryid str7 date float value "ARG" "2014" 0.3386826 "ARG" "2015" 0.1357258 "ARG" "2016" 0.3204299 "ARG" "2017" 0.1795446 "ARG" "2018" 0.3334255 "ARG" "2019" 0.3455194 "ARG" "2020" 0.3332398 "ARG" "2013-Q1" 2185.1 "ARG" "2013-Q2" 3251.5 "ARG" "2013-Q3" 2832.1 "ARG" "2013-Q4" 1552.9 "ARG" "2014-Q1" 1128.5 "ARG" "2014-Q2" -1496.9 "ARG" "2014-Q3" 2432.7 "ARG" "2014-Q4" 3001 "ARG" "2015-Q1" 3514.3 "ARG" "2015-Q2" 3360.8 "ARG" "2015-Q3" 2702.3 "ARG" "2015-Q4" 2181.6 end
And the code below is currently in my procedure.
Code:
gen ydate = yearly(date, "Y") format ydate %ty gen qdate = quarterly(date, "YQ") format qdate %tq drop year gen year = yq(ydate, qdate)
Code:
countryid year value "ARG" "2014" 0.3386826 "ARG" "2015" 0.1357258 "ARG" "2016" 0.3204299 "ARG" "2017" 0.1795446 "ARG" "2018" 0.3334255 "ARG" "2019" 0.3455194 "ARG" "2020" 0.3332398 "ARG" "2013q1" 2185.1 "ARG" "2013q2" 3251.5 "ARG" "2013q3" 2832.1 "ARG" "2013q4" 1552.9 "ARG" "2014q1" 1128.5 "ARG" "2014q2" -1496.9 "ARG" "2014q3" 2432.7 "ARG" "2014q4" 3001 "ARG" "2015q1" 3514.3 "ARG" "2015q2" 3360.8 "ARG" "2015q3" 2702.3 "ARG" "2015q4" 2181.6
Enzo
Comment