On Aug 26, 2004, at 6:38 AM, [email protected] wrote:
it's the first time I analyse time series data in Stata. My quarterly
date variable looks like this:
. list date in 1/12, separator(4)
� � +---------+
� � | � �date |
� � |---------|
�1. | � �1960 |
�2. | 1960.25 |
�3. | �1960.5 |
�4. | 1960.75 |
� � |---------|
�5. | � �1961 |
�6. | 1961.25 |
�7. | �1961.5 |
�8. | 1961.75 |
� � |---------|
�9. | � �1962 |
10. | 1962.25 |
11. | �1962.5 |
12. | 1962.75 |
� � +---------+
Try:
gen year = floor(date)
gen qtr = (date - year)/4 + 1
gen mydate = yq(year,qtr)
format mydate %tq
drop year qtr // optional
list date mydate in 1/12, sep(4)
You should get:
+------------------+
| date mydate |
|------------------|
1. | 1960 1960q1 |
2. | 1960.25 1960q2 |
3. | 1960.5 1960q3 |
4. | 1960.75 1960q4 |
|------------------|
5. | 1961 1961q1 |
6. | 1961.25 1961q2 |
7. | 1961.5 1961q3 |
8. | 1961.75 1961q4 |
|------------------|
9. | 1962 1962q1 |
10. | 1962.25 1962q2 |
11. | 1962.5 1962q3 |
12. | 1962.75 1962q4 |
+------------------+
HTH.
-- Mike
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/