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
Interaction Term becomes insignificant after adding a non-correlated control variableDear STATA experts, I run an OLS regression including an interaction term. Code: reg DepVar In…
DiD multiple same years across statesI am attempting DID with having states from one year 1991 being compared to states from 1992 and so …
Need alternative to using the total command with matrix var = [e(b)]Hello, I provided some code below, but briefly explain my issue first. I am creating tables in Sta…
System GMMHi I would like to appy twostep system GMM with xtabond2 command. But I am not sure whether my model…
Entering missing calendar datesHi I have a health data set that has 1078 individuals and 75 variables and spans 7 years. Each indi…
Subscribe to:
Post Comments (Atom)
0 Response to Re: Converting a string variable to a date variable
Post a Comment