Intro To Panel Data Analysis Using Stata-UiTM Perlis-Mei2015
Intro To Panel Data Analysis Using Stata-UiTM Perlis-Mei2015
By:
Mahyudin Ahmad, PhD
UiTM Perlis.
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 1
Outline of Panel Data workshop
Day 1-Morning – Session 1 Day 2-Morning – Session 2 contd.
1. Stata 11: an introduction 1. Model 3: FE-Within
2. Setting up 2. Model 4: RE
3. Importing data to Stata 11 3. Exercises
4. Basic commands
5. Panel data commands Day 2-Evening – Session 2 contd.
6. Hands-on with Stata 11 1. Test and model selection
2. Conclusion
Day 1-Evening – Session 2 3. Exercises
1. Intro to Panel Data Analysis
2. Model 1: POLS
3. Model 2: FE-LSDV
4. Exercises
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 2
Session 1:
INTRODUCTION TO
STATA 11
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 3
Learning outcomes
At the end of the session 1, participants will be able to:
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 4
1. Stata 11: an introduction
Stata 11 interface
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 5
1. Stata 11: an introduction
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 6
1. Stata 11: an introduction
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 7
1. Stata 11: an introduction
Log
begin
Data
editor
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 8
2. Setting up - basics
It is advisable to do these steps before embarking on any regression. The log file
keeps the whole works you did including the regression results/outputs.
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 9
2. Setting up - basics
List of previously
executed
command
Output/result
appear here
We write command
here
List of variables
appear here once
we load the data
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 10
2. Setting up - basics
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 11
2. Setting up - basics
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 12
2. Setting up – do file
Some people may think they prefer “click and execute” style, but I guess having
a record of your work is paramount since research is a long term process. You
may want to reuse your preferable method in future using different sets of data.
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 13
2. Setting up – do file
Creating a do file
Create/open
do file
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 14
2. Setting up – do file
Sample do file
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 15
2. Setting up – do file
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 16
2. Setting up – do file
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 17
2. Setting up – do file
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 18
2. Setting up – do file
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 19
3. Importing data to Stata 11
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 20
3. Importing data to Stata 11
Once you have sorted your data, follow these
steps to import data to Stata 11 from Excel.
1. From you excel file, copy all data
including the variable names
2. Click data editor button,
3. Data editor window will popup, then
4. Highlight top left cell, and press Ctrl+V
to paste your data,
5. You’ll be asked how to treat first row:
as data or variable names
6. Choose: Treat first row as
variable names
7. Save it as <your dta
filename>.dta . The data will be
saved in your working folder earlier set
by cd command.
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 21
3. Importing data to Stata 11
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 22
3. Importing data to Stata 11
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 23
3. Importing data to Stata 11
Importing *.csv data file using point and click menu:
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 24
3. Importing data to Stata 11
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 25
4. Basic commands
Commands normally used (the list below is not extensive, and you may learn
yourself from sources widely available in the internet):
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 26
4. Basic commands
label var <var id> "label" : to label a variable (see slide 21)
For data denoted in binary, eg. data for airline variable i which are denoted
in binary number (1, 2, ….,6) to reflect 6 types of airlines, we can label define
the binary numbers for easier reference.
Once the data loaded, we first label the variable i as “Airlines in US” and
then define its binary data with appropriate definitions. The commands are:
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 28
4. Basic commands
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 29
Hands-on with Stata11
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 30
5. Panel data command
Commands normally used in panel data analysis. Panel data commands start
with xt
help xt : to obtain help files on xt command
xtset id year : to inform Stata that our data is panel
xtsum: to summarize data, will give overall, between and within stats and
obs
xtdes <var id> : to describe a variable
xtreg : to start panel regression. We’ll look more after this
xtabond: difference GMM command
xtdpdsys: system GMM command
xtabond2: this command is a lot better than the above two, it’s capable of
doing both dGMM and sGMM. We’ll look more after this.
We’ll learn more commands from time to time during this workshop.
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 31
5. Panel data command
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 32
6. Simple example
Source: http://www.princeton.edu/~otorres/Panel101.pdf
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 33
Session 2:
INTRODUCTION TO PANEL DATA
ANALYSIS USING STATA 11
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 34
Outline
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 35
Learning outcomes
At the end of the workshop, participants will be able to:
3. perform empirical analyses for panel data and interpret the results
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 36
1. Introduction
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 37
1. Introduction
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 38
1. Introduction
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 39
2. Advantages and Disadvantages
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 40
2. Advantages and Disadvantages
Advantages:
larger sample size data more informative, more variations
(normally between variations > within variations), less
collinearity (as is often time series), leading to increased
precision of estimates.
Ability to study the dynamics – repeated cross sectional
observations – adjustment over times
Ability to account for heterogeneity across individuals often
ignored in pooled data – more robust against misspecification
due to omitted variable bias
Disadvantages:
Data availability/maintenance,
measurement error/distortions
Self-selection bias – other factors than the group heterogeneity
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 41
3. Recall: CLRM assumptions
Table 3.1 above is taken from page 37, “Applied Econometrics”, Asteriou & Hall, 2nd ed. 2011, Palgrave Macmillan.
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 42
3. Recall: CLRM assumptions
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 43
4. Panel data models
Pooled OLS
Fixed Effects
Least Square Dummy Variables
Within estimator
Between estimator
Random Effects
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 44
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 45
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 46
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 47
4. Panel data models
Pooled OLS
In this case, we simply pooled the data (prepare the data in panel,
hence higher number of observations) and run OLS.
Pooled OLS – subject to heterogeneity bias if assumption εit =iid error
does not hold
After loading the data, run the command : regress y x1
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 48
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 49
4. Panel data models
What if xit correlates with εit , due to the presence of fixed effects, since
εit = vi + uit ? heterogeneity bias!
Fixed effects may come from individual or entity (ability, country
access to shore) and time (macro variables, policies, etc)
In panel data model, we can represent both fixed effects as:
One-way fixed effect:
o entity fixed effect : yit 1 xit vi uit or
o time fixed effect yit 1 xit t uit
Two-way fixed effects, i.e. include both entity AND time fixed
effects y x v u
it 1 it i t it
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 50
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 51
4. Panel data models
LSDV
N
yit i Di 1 xit uit (3)
i 1
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 52
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 53
4. Panel data models
yi vi 1 xi ui (4)
Where :
T T T
y x u
1 1 1
yi it , xi it and ui it
T t 1
T t 1
T t 1
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 54
4. Panel data models
Within estimation:
Now take Eq.(2) – Eq.(4)
yit yi (vi 1 xit uit ) - (vi 1 xi ui )
yit yi 1 ( xit xi ) (uit ui )
Now vi is eliminated, no heterogeneity bias anymore
“Deviation from individual mean” form
yit 1xit uit (5)
Run OLS to Eq.(5)
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 55
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 56
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 57
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 58
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 59
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 60
Hands-on with Stata11
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 61
4. Panel data models
Random Effects
The rationale behind random effects model is that, unlike the fixed
effects model, the variation across entities is assumed to be random
and uncorrelated with the predictor or independent variables
included in the model.
“…the crucial distinction between fixed and random effects is whether the unobserved
individual effect embodies elements that are correlated with the regressors in the
model, not whether these effects are stochastic or not” [Green, 2008, p.183]
In other words: Heterogeneity in FE is due to individual differences,
and it correlates with X, BUT in RE, the differences are rather random
and uncorrelated with X.
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 62
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 63
4. Panel data models
RE model – the transformation:
yit yi 1 ( xit xi ) (1 )vi (uit ui ) (6)
u2
where 1 -
T v2 u2
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 64
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 65
4. Panel data models
Between estimator
yi vi 1 xi ui
Not so useful, as it wipes out time variations completely.
Stata command to estimate between estimator:
xtreg y x1 x2 x3, be
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 66
4. Panel data models
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 67
5. Tests for Model Selection
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 68
5. Tests
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 69
5. Tests
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 70
5. Tests
testparm i.year
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 71
5. Tests
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 72
Hands-on with Stata11
Continue hands-on 2 with Stata 11, we are still using “uum do file
2 handson” file
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 73
6. The best methods
Fixed effect estimator of β remains consistent even if the true model is not fixed
effect
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 74
7. Summary
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 75
7. Summary
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 76
8. Exercise
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 77
8. Exercise
Pooled OLS
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 78
8. Exercise
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 79
8. Exercise
FE - Within estimation
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 80
8. Exercise
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 81
8. Exercise
Note: if you want the value of theta, add word theta after the above command
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 82
8. Exercise
Comparing POLS, LSDV, WE and RE coefficients
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 84
8. Exercise
Testing for time fixed effect:
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 85
8. Exercise 2
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 86
THE END
Thank you
Introduction to Stata11 & Panel Data Analysis –UiTM Perlis, 8 Mei 2015 Page 87