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:
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:
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:
(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:
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:
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:
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:
Regression
First, use the command: xtset sample name time to define panel data.
For example:
xtset province year
As shown:
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:
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!