2

Click here to load reader

Stata & Time Series – Getting Started - · PDF fileIntensifying Course Applied Econometrics & Statistics Stata & Time Series Stata & Time Series – Getting Started Most time series

  • Upload
    doantu

  • View
    232

  • Download
    11

Embed Size (px)

Citation preview

Page 1: Stata & Time Series – Getting Started - · PDF fileIntensifying Course Applied Econometrics & Statistics Stata & Time Series Stata & Time Series – Getting Started Most 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 consistof time series. But Stata usually does not know or recognize that. You have to giveStata an understanding of the time series nature of your data with the commandtsset. This command is simply a way for you to tell Stata which variable in yourdata set represents time; tsset then sorts and indexes the data appropriately foruse with the time series commands. Once your data set has been tsset, you can useStata’s time series operators in data manipulation or programming using that dataset and when specifying the syntax for most time series commands. Stata has timeseries operators for representing the lags, leads, differences, and seasonal differencesof a variable. In the following you find a detailed explanation of how to use tssetin 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 canbe used easily. Let’s assume you have yearly data and the variable year is in yourdata 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

+-------+| var1 ||-------|

1. | 18369 |2. | 17661 |3. | 16340 |4. | 16268 |5. | 19340 |

|-------|6. | 19471 |7. | 16909 |8. | 14820 |9. | 10274 |

10. | 6740 ||-------|

11. | 4365 |

c© Martin Halla 1

Page 2: Stata & Time Series – Getting Started - · PDF fileIntensifying Course Applied Econometrics & Statistics Stata & Time Series Stata & Time Series – Getting Started Most time series

Intensifying Course Applied Econometrics & Statistics Stata & Time Series

12. | 6189 |13. | 6479 |14. | 6894 |15. | 6502 |

...

Let’s say you know that the first observation corresponds to July 1995 and continueswithout 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 timetime variable: time, 1995m7 to 2004m6

delta: 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