Introduction
When working with time-series data, especially in economics, you will often need to enter and analyze data that are sorted by quarter. Creating quarters can be difficult in some statistical problems and easier in others. For example, eViews makes entering quarterly data quite easy. The process is a little harder in Stata, but, in this blog, we’ll show you how to do it.
Entering Your Data
The first step in creating quarters in Stata is to specify the total number of quarters you want in your dataset, tell Stata what the first quarter is, and then apply Stata’s quarter format so that the display looks intuitive. Let's go step by step. Begin by entering the following line of code:
set obs 84
This merely tells Stata that you will have 84 quarters in your dataset.
Next, tell Stata what the very first quarter is going to be and ask Stata to automatically fill in the remaining quarters.
gen quarter = tq(2001q3) + _n-1
You get:
That doesn’t look like quarters! The reason is that Stata has its own machine language for representing quarters, so you need to add a line of code to format quarters in an intuitive way. Add this line of code:
format %tq quarter
And now you get:
That’s better! If you scroll down, you’ll see that Stata has created a sequential variable, quarter, that runs from 2001q3 to 2022q2.
Declare Quarters to be Time-Series Data
Before you can create time-series graphs or attempt time-series analysis, you need to declare quarters to be a time-series variable in Stata. You can do that with this code snippet:
tsset quarter
In future blog entries, we’ll dive into time-series analysis in greater detail.
BridgeText can help you with all of your statistical analysis needs.