Hey,
I'm sorry to be bothering you with something that should be trivial, but I can't extract the quarter from a given year.
This is my result table.
datestr was my given variable and is formatted as string
date I generated as
gen date = date(datestr, "MDY")
format date %td
quarter I genarated as
gen quarter= date(datestr, "MDY")
format quarter %tq
It didn't work. The year and the quarter were both wrong.
I dropped it and tried with
gen quarter= quarter(datestr)
can't generate from strings
gen quarter= quarter(date)
format quarter %tq
And I get this table. Both are wrong, again.
Experimentally I reformatted the date variable to %tq. I not only don't get the correct values, I get values that do not match the quarter variable.
What am I doing wrong? I tried searching through the FAQ archives, but I can't seem to find an answer. I even went to the fifth page of google, at which point I just gave up.
Any help will be appreciated!
I'm sorry to be bothering you with something that should be trivial, but I can't extract the quarter from a given year.
This is my result table.
datastr | date | quarter |
September 11, 1992 | 11sep1992 | 1960q4 |
October 1,1992 | 01oct1992 | 1961q1 |
June 15, 1994 | 15jun1994 | 1960q3 |
June 20, 1994 | 20jun1994 | 1960q3 |
. | . | . |
December 31, 2004 | 31dec2004 | 1961q1 |
January 3, 2005 | 03jan2005 | 1960q2 |
May 15, 2012 | 15may2012 | 1960q3 |
date I generated as
gen date = date(datestr, "MDY")
format date %td
quarter I genarated as
gen quarter= date(datestr, "MDY")
format quarter %tq
It didn't work. The year and the quarter were both wrong.
I dropped it and tried with
gen quarter= quarter(datestr)
can't generate from strings
gen quarter= quarter(date)
format quarter %tq
And I get this table. Both are wrong, again.
Experimentally I reformatted the date variable to %tq. I not only don't get the correct values, I get values that do not match the quarter variable.
What am I doing wrong? I tried searching through the FAQ archives, but I can't seem to find an answer. I even went to the fifth page of google, at which point I just gave up.
Any help will be appreciated!
Comment