I'm getting a weird result when trying to apply the "quarter" and "year" commands to a date series. I generate the date series with:
gen date = tq(2004q1) + _n-1
format date %tq
This gives me a date series starting from 1q2004.
I then want to create a quarter variable that just shows the quarter - 1,2,3,4. I do this with
gen quarter = quarter(date).
What I end up with looks like this:
+------------------+
| date quarter |
|------------------|
1. | 2004q1 2 |
2. | 2004q2 2 |
3. | 2004q3 2 |
4. | 2004q4 2 |
5. | 2005q1 2 |
|------------------|
6. | 2005q2 2 |
7. | 2005q3 3 |
8. | 2005q4 3 |
9. | 2006q1 3 |
10. | 2006q2 3 |
|------------------|
11. | 2006q3 3 |
12. | 2006q4 3 |
13. | 2007q1 3 |
14. | 2007q2 3 |
What am I doing wrong with "quarter"?
Thank you!
gen date = tq(2004q1) + _n-1
format date %tq
This gives me a date series starting from 1q2004.
I then want to create a quarter variable that just shows the quarter - 1,2,3,4. I do this with
gen quarter = quarter(date).
What I end up with looks like this:
+------------------+
| date quarter |
|------------------|
1. | 2004q1 2 |
2. | 2004q2 2 |
3. | 2004q3 2 |
4. | 2004q4 2 |
5. | 2005q1 2 |
|------------------|
6. | 2005q2 2 |
7. | 2005q3 3 |
8. | 2005q4 3 |
9. | 2006q1 3 |
10. | 2006q2 3 |
|------------------|
11. | 2006q3 3 |
12. | 2006q4 3 |
13. | 2007q1 3 |
14. | 2007q2 3 |
What am I doing wrong with "quarter"?
Thank you!
Comment