Home >Common Problem >What are the steps for stata panel data regression?

What are the steps for stata panel data regression?

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-07-23 13:06:1880677browse

What are the steps for stata panel data regression?

stata panel data regression steps:

Step 1: Import data

Command:

insheet using 文件路径

Such as:

insheet using C:STUDYpapertaxi.csv

Please note: there cannot be Chinese characters in the table, otherwise an error will occur. There cannot be null values ​​in the panel data. Please replace the positions with no data with 0.

You can also directly copy and paste the data into stata's data editor, as shown in the figure:

What are the steps for stata panel data regression?

Step 2: Adjust the format

First, please rename the var1 representing the sample

Command:

rename var1样本名

For example:

rename var1 province

Next, convert the data into the format of panel data

Command:

reshape long var,i(样本名)

For example:

reshape long var,i(province)

where var represents all years (var2, var3, var4...)

The converted format is as follows Figure:

What are the steps for stata panel data regression?

Continue to rename after successful conversion, where _j here represents the year in the original table, var represents the name of the variable, the command is as follows:

rename _j year
rename var taxi

Step 3: Sort

Command: sort Variable name

For example:

sort province year

It means to sort the province in ascending order, and then according to The arranged province numbers are arranged in the year column, as shown in the figure:

What are the steps for stata panel data regression?

(Although in many cases the data already meets the requirements before performing sort, please be sure to do so just in case. Do this)

Finally, save.

At this point, the preliminary data processing of a variable is completed. Please process all variables in the same way. Please use the command: clear to reset stata before processing new variables.

For the sake of convenience, a variable named so2 is processed here. As shown in the picture:

What are the steps for stata panel data regression?

Related recommendations: "FAQ"

Step 4: Merge data

Open any dta file of a processed variable as the base table (it is recommended to use the dta file of the dependent variable, here so2 is used as the dependent variable)

Command: merge sample name time using file path

For example:

merge province year using C:STUDYpapertaxi.csv

It means to add taxi data to the data table of so2, as shown in the figure:

What are the steps for stata panel data regression?

Then use the command:

tab _merge

Check the difference of the data. Under normal circumstances, the percentage of the _merge: 3 column should be 100%, as shown in the figure:

What are the steps for stata panel data regression?

Then use the command: drop _merge, remove the _merge column in the data table.

Then reuse the command: sort sample name time

For example: sort province year to sort the newly generated table.

Similarly, add all variables to the basic table, as shown in the figure:

What are the steps for stata panel data regression?

Regression

First, use the command: xtset sample name time to define panel data.

For example:

xtset province year

As shown:

What are the steps for stata panel data regression?

Then use the command:

xtreg dependent variable independent variable for regression Analysis

For example:

xtreg so2 taxi busload drivers roadlength

As shown in the figure:

What are the steps for stata panel data regression?

The above is the detailed content of What are the steps for stata panel data regression?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn