Reputation: 13
I have some panel data with quarterly data in string format (imported from .csv file).
The name of the variable is datacqrt
and it is in the format "YYYY"Q"Q"
say 1998Q3
. So I have it from 1966Q1
to 2014Q4
for each of the around 200 categories.
I am following the Stata guide and creating a new variable like this
generate time = date(datacqtr,"YQ")
but then it creates only missing values.
How do I make Stata understand the variable datacqrt
is a time?
Upvotes: 0
Views: 273
Reputation: 37208
The function date()
is for creating daily dates in Stata terms, i.e. days with an origin 0 at 1 January 1960. This is documented at length in (e.g.) help dates and times
but is even clearer with the synonym daily()
.
You need the function quarterly()
, for example:
. di %tq quarterly("2015q3", "YQ")
2015q3
. di %3.0f quarterly("2015q3", "YQ")
222
In your case you want something like
gen qdate = quarterly(datacqrt, "YQ")
Upvotes: 2