Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 73370

Convert variable from string to date

$
0
0
Hi everyone,

I have a simple question: how do I convert a string variable to a date variable? The variable "date" currently contains years/quarters. Here is sample data:

1998q1
1998q2
1998q3
1998q4
1999q1
...

I tried the following:

gen date2 = date(date, "yq")
format date2 %tq

but I receive the following message: "384 missing values generated". I separately tried using "YQ", "tq", and "TQ" (instead of "yq") but this did not help.

A similar query has been raised before on these boards (http://www.statalist.org/forums/foru...-date-variable), so I think the issue has to do with the "yq".

Thanks very much for any assistance.


Viewing all articles
Browse latest Browse all 73370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>