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

What are the steps for stata panel data regression?

爱喝马黛茶的安东尼
Release: 2019-07-23 13:06:18
Original
80579 people have browsed it

What are the steps for stata panel data regression?

stata panel data regression steps:

Step 1: Import data

Command:

insheet using 文件路径
Copy after login

Such as:

insheet using C:STUDYpapertaxi.csv
Copy after login

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样本名
Copy after login

For example:

rename var1 province
Copy after login

Next, convert the data into the format of panel data

Command:

reshape long var,i(样本名)
Copy after login

For example:

reshape long var,i(province)
Copy after login

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
Copy after login

Step 3: Sort

Command: sort Variable name

For example:

sort province year
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template