Hello,
My date variable (moyr) could not be used when I declared my dataset to be monthly panel data. As seen below, moyr is a string variable that is composed of YYYY-MM.
. list moyr in 1/5
+---------+
| moyr |
|---------|
1. | 2017-01 |
2. | 2017-02 |
3. | 2017-03 |
4. | 2017-04 |
5. | 2017-05 |
+---------+
Thus, I generate a new date variable by using the code: generate date = date(moyr,"YM"). However, values for the date variable are not readable.
. list moyr date in 1/5
+-----------------+
| moyr date |
|-----------------|
1. | 2017-01 20820 |
2. | 2017-02 20851 |
3. | 2017-03 20879 |
4. | 2017-04 20910 |
5. | 2017-05 20940 |
+-----------------+
Thus, I reformatted the date variable to be YYYY-MM using the code: format %tmCCYY-NN date.
. list moyr date in 1/5
+-------------------+
| moyr date |
|-------------------|
1. | 2017-01 3695-01 |
2. | 2017-02 3697-08 |
3. | 2017-03 3699-12 |
4. | 2017-04 3702-07 |
5. | 2017-05 3705-01 |
+-------------------+
However, values in the date variable are still not readable. Any advice would be greatly appreciated. Thank you.
Related Posts with Re: Converting a string variable to a date variable
Using MarginsPlot to visualize Quadratics in Panel DataDear Statalist community, I need help with two things: One, I want to use the margins and marginsp…
Reshaping a both long and wide dataset into only long formHi. I have medical prescription data ranging from 2007-2012 in the format below. The two identifying…
Is Stata freaking out?This question is perhaps a bit weird. I've run the same do-file on the same .dta file multiple times…
Moderating Vs. average marginal effects of the modelsHi, Statalisters: I am not so much good in posting on the forum, please excuse me for not adhering t…
Endless iteration using Panel Data ppml zero-inflated poissonI have a dataset of 5 years panel data of more than 30,000 cities. However, when I run regression pp…
Subscribe to:
Post Comments (Atom)
0 Response to Re: Converting a string variable to a date variable
Post a Comment