# How to set the ‘Time variable’ for time series analysis in STATA

Time series analysis works on all structures of data. It comprises methods to extract meaningful statistics and characteristics of data. Time series test is applicable on datasets arranged periodically (yearly, quarterly, weekly or daily). This article explains how to set the ‘Time variable’ to perform time series analysis in STATA. The following points are covered here:

1. Introduction to the dataset.
2. Processing of dataset in STATA.
3. Setting ‘Time variable’ to perform time series analysis.

## Introduction to dataset

Time series analysis is performed on datasets large enough to test structural adjustments.  The next few articles explain how to conduct time series analysis. For this purpose, a case dataset of the following indicators of the Indian economy is chosen. These indicators are:

• Gross Domestic Product (GDP),
• Gross Fixed Capital Formation (GFC) and
• Private Final Consumption (PFC)

Data is presented in USD billion format. It has been arranged quarterly for the period 1996 to 2016, comprising of 83 observations. The first step is to import or copy the data to STATA.

1. Open STATA application.
2. Click on ‘Data Editor’ as shown in the figure below.

A separate window named ‘Data Editor’ will appear. Copy the dataset from the respective sources and paste it into the window as shown in the figure below.

Use 5E26B3F82A6CE to save 271 on 62001 – 70000 words standard order of Thesis Writing.

## Processing of a dataset in STATA

As the figure above shows, the dataset has four columns; ‘Date’, ‘GDP’, ‘GFC’ and ‘PFC’. The data is arranged on a quarterly basis. The ‘Date’ column in the ‘Data Editor’ window appears in red colour. This indicates that this data contains either alphabets or symbols. However, STATA accepts only numerical values. Therefore, the first step is to format the ‘Date’ variable. For this follow the below steps.

1. Select ‘Date’ variable in ‘Data Editor’.
2. Click on ‘Data’.
3. Select ‘Create or Change Data’.
4. Click on ‘Create New Variable’ as shown below.

A dialogue box named ‘Generate-create a new variable’ will appear as shown below. Fill in two options; ‘Variable name’ and ‘Specify a value or an expression.

Here new ‘Date’ variable is named as ‘date2’. To fill the second option, click on ‘Create’ as shown in the figure below. Another window, ‘Expression Builder will appear. Select ‘Dates and times’ from the first box and then double click on ‘date()’ from the second box.

‘Expression builder’ will appear with ‘date()’ as shown in the figure below. Fill the bracket by naming the variable and expression to format. Furthermore, the ‘Date’ variable needs formatting. Therefore, it is written as ‘date (date,“YMD”)’. ‘YMD’ refers to the year, month and day since the selected data is in quarterly format with daily dates.

OR

Use STATA command:

`generate Date2 = date(date,"YMD")`

Then click on ‘OK’. ‘Create New Variable’ window will appear as shown in the figure below. Click on ‘OK’ to generate the variable ‘Date2’.

A new variable ‘Date2’ has appeared in the ‘Data Editor’ window as shown in the figure below. The ‘Date’ variable has been reframed into a new variable ‘Date2’ with numbers. Therefore, the ‘Data Editor’ window will now accept this variable. However, the problem with this variable is that the numbers do not indicate the exact dates. Therefore, to view ‘Date2’ variables with dates, format the variable.

To format:

1. Select ‘Date2’ variable.
2. Select ‘Variable Properties’ in the ribbon as shown in figure below.

A dialogue box ‘Variable properties’ will appear. Click on three dots against ‘Format’ as shown in the figure below.

A separate window ‘Create Format’ will appear like the figure below. Select ‘Daily’ in ‘Type of data’ as the ‘Date’ variable is in a daily format. Then select any sample format. Then click on ‘OK’.

OR

Use STATA command:

`format %td Date2`

The ‘date2’ variable will reappear as shown in the figure below.

Since the data is in a quarterly format, you can also reframe the ‘date2’ variable in quarters. To do this, see Figure 2 and open the ‘Create New Variable’ window. Frame a new date variable called ‘Quarterly’. Write “qofd(Date2)” in the ‘Expression’ window (since the variable to be reframed is ‘Date2’).

OR

Use STATA command:

`generate Quarterly = qofd(Date2)`

‘Quarterly’ variable will appear in the ‘Data Editor’ window as shown in the figure below.

This variable does not display the exact quarters. Instead, it is represented in numeric form. Therefore format the variable by following the steps shown in Figures 9, 10 and 11. However this time select ‘Quarterly’ in the first box and ‘Any Quarter Format’ in the second box as shown in the figure below.

OR

Use STATA command:

`format %tq Quarterly`

Finally, the ‘Date’ variable is arranged in ‘Quarterly’ format as shown in the figure below.

##### Need Our Services?
###### Econometrics & Statistics Modelling Services
Need Help, Whatsapp Us Now