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
Trouble with reshapeHi all! I am working with DHS data and I am analyzing marriage institutions and siblings' marriage …
Standard deviationHey guys, i could need some assistance with the following issue. Dataset Station__name Year Mea…
Transforming a categorical variable into 1 categorical and 1 binaryHello! Can you tell me how to pull out one of the 4 categorical options of the education variable so…
Autocorrelation Parameter Estimates ≥ 1 in SP Stata ManualI noticed a 3 examples in the Spatial Autoregressive Models Reference Manual (Release 16) that 3 exa…
Creating a new variable, from specific values of 3 existing variablesHello, I am really bad in stata and need help. I have a database with 3 variables: birthcountry, aut…
Subscribe to:
Post Comments (Atom)
0 Response to Re: Converting a string variable to a date variable
Post a Comment