Stata & Time Series – Getting Started

594 downloads 1742 Views 121KB Size Report
Intensifying Course Applied Econometrics & Statistics ... Most time series commands in Stata assume that Stata knows that your data consist of time series.
Intensifying Course Applied Econometrics & Statistics

Stata & Time Series

Stata & Time Series – Getting Started Most time series commands in Stata assume that Stata knows that your data consist of time series. But Stata usually does not know or recognize that. You have to give Stata an understanding of the time series nature of your data with the command tsset. This command is simply a way for you to tell Stata which variable in your data set represents time; tsset then sorts and indexes the data appropriately for use with the time series commands. Once your data set has been tsset, you can use Stata’s time series operators in data manipulation or programming using that data set and when specifying the syntax for most time series commands. Stata has time series operators for representing the lags, leads, differences, and seasonal differences of a variable. In the following you find a detailed explanation of how to use tsset in the two most important cases.

Case 1: Time Series Data with a Time Variable In the case you have time series data with a time variable, the tsset command can be used easily. Let’s assume you have yearly data and the variable year is in your data set . tsset year, yearly This works equivalent with quarterly and monthly data, see help tsset.

Case 2: Time Series Data without a Time Variable Perhaps you have time series data and no time variable: . list var1

1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.

+-------+ | var1 | |-------| | 18369 | | 17661 | | 16340 | | 16268 | | 19340 | |-------| | 19471 | | 16909 | | 14820 | | 10274 | | 6740 | |-------| | 4365 |

c Martin Halla

1

Intensifying Course Applied Econometrics & Statistics

12. 13. 14. 15.

| | | |

6189 6479 6894 6502 ...

Stata & Time Series

| | | |

Let’s say you know that the first observation corresponds to July 1995 and continues without gaps. You can create a monthly time variable and format it by typing: . generate time = m(1995m7) + _n -1 . format t %tm You can now tsset your data set and list . tsset time time variable: delta:

time, 1995m7 to 2004m6 1 month

. list time var1 +-----------------+ | time var1 | |-----------------| 1. | 1995m7 18369 | 2. | 1995m8 17661 | 3. | 1995m9 16340 | 4. | 1995m10 16268 | 5. | 1995m11 19340 | |-----------------| 6. | 1995m12 19471 | 7. | 1996m1 16909 | 8. | 1996m2 14820 | 9. | 1996m3 10274 | 10. | 1996m4 6740 | |-----------------| 11. | 1996m5 4365 | 12. | 1996m6 6189 | 13. | 1996m7 6479 | 14. | 1996m8 6894 | 15. | 1996m9 6502 | ...

c Martin Halla

2