📚 Introductory Econometrics with MORISTAT
A Practical Guide to Empirical Analysis
Naguib Lallmahomed · naglal@linux-mauritius.com · 2026-06-14
Chapter 8: Panel Data and Difference-in-Differences
🎯 Learning Objectives
Upon completing this chapter, you will be able to:
- Understand what panel data is and why it is useful
- Distinguish between pooled OLS, fixed effects, and random effects
- Understand the Hausman test for model selection
- Implement Difference-in-Differences (DiD) for causal inference
- Understand the parallel trends assumption
- Use MORISTAT to analyse panel data
8.1 What is Panel Data?
Panel data (also called longitudinal data) combines both:
- Cross-sectional data (multiple individuals/units at one point in time)
- Time series data (multiple time periods for one individual/unit)
Example: Data on 100 firms over 10 years (100 × 10 = 1,000 observations).
- Each firm is observed in each year
- Variables: sales, profits, employees, R&D spending, etc.
Panel data notation:
Yit = β₀ + β₁Xit + uit
- i = individual/unit (e.g., firm, country, person)
- t = time period (e.g., year, quarter, month)
- Xit = independent variable for individual i at time t
8.1.1 Advantages of Panel Data
- More information → more efficient estimates
- Controls for unobserved heterogeneity (fixed effects)
- Allows for dynamics (lagged variables)
- Better for causal inference (DiD)
8.2 Panel Data Models
8.2.1 Pooled OLS
Ignore the panel structure and treat all observations as independent:
Yit = β₀ + β₁Xit + uit
- Advantage: Simple
- Disadvantage: Ignores individual-specific effects → bias if unobserved heterogeneity exists
8.2.2 Fixed Effects (FE)
Allow each individual to have its own intercept (captures time-invariant unobserved heterogeneity):
Yit = β₀ + β₁Xit + αi + uit
- αi = individual-specific fixed effect (captures all time-invariant unobserved factors)
- Within estimator: Uses variation within each individual over time
- Key assumption: E(uit|Xit, αi) = 0
8.2.3 Random Effects (RE)
Assume αi is random and uncorrelated with Xit:
Yit = β₀ + β₁Xit + νi + uit
- νi = random individual-specific error term
- Key assumption: E(νi|Xit) = 0 (no correlation between νi and Xit)
- Advantage: More efficient if the assumption holds
- Disadvantage: Biased if the assumption is violated
8.2.4 Hausman Test
Tests whether FE or RE is appropriate:
- H₀: RE is consistent (νi is uncorrelated with Xit)
- H₁: RE is inconsistent (use FE)
- If p-value < 0.05 → reject H₀ → use Fixed Effects
- If p-value ≥ 0.05 → fail to reject H₀ → use Random Effects
8.3 Difference-in-Differences (DiD)
8.3.1 What is DiD?
DiD is a quasi-experimental method for estimating causal effects using panel data with a treatment and control group.
Example: Effect of a minimum wage increase on employment.
- Treatment group: States that increased the minimum wage
- Control group: States that did not increase the minimum wage
- DiD estimate = (Change in treatment) − (Change in control)
8.3.2 The DiD Model
Yit = β₀ + β₁ × Treati + β₂ × Postt + β₃ × (Treati × Postt) + uit
- Treati = 1 if treated, 0 if control
- Postt = 1 after intervention, 0 before
- β₃ = DiD estimator (the causal effect of treatment)
8.3.3 Parallel Trends Assumption
Key Assumption: In the absence of treatment, the treatment and control groups would have followed parallel trends over time.
- This assumption is not directly testable (counterfactual)
- Can be visually assessed by plotting trends before treatment
- Pre-treatment trends should be similar (parallel)
8.4 MORISTAT Examples
8.4.1 Panel Data Format
Panel data in CSV format:
Firm,Year,Sales,Profits,Employees
1,2020,100,10,50
1,2021,110,12,55
1,2022,120,14,60
2,2020,200,20,80
2,2021,210,22,85
2,2022,220,24,90
8.4.2 Pooled OLS in MORISTAT
MORISTAT> LOAD panel_data.csv
MORISTAT> REGRESS Sales ~ Profits Employees
8.4.3 DiD Example
MORISTAT> LOAD did_data.csv
MORISTAT> REGRESS Employment ~ Treat Post Treat_Post
8.5 Practical Exercises
Exercise 8.1: Fixed vs Random Effects
You have panel data on 50 countries over 10 years. You want to estimate the effect of trade openness on GDP growth.
- If unobserved country-specific factors (e.g., culture, institutions) are correlated with trade openness, which method would you use?
- If these factors are uncorrelated with trade openness, which method would you use?
- How would you decide which method to use?
Solution:
- Fixed Effects – if unobserved factors are correlated with trade openness
- Random Effects – if unobserved factors are uncorrelated with trade openness
- Use the Hausman test to decide: p < 0.05 → FE; p ≥ 0.05 → RE
Exercise 8.2: Interpreting DiD
You estimate the following DiD model:
Employment̂ = 100 + 5 × Treat + 10 × Post + 15 × (Treat × Post)
- What is the employment level in the control group before the treatment?
- What is the employment level in the treatment group before the treatment?
- What is the causal effect of the treatment on employment?
Solution:
- Control before: 100
- Treatment before: 100 + 5 = 105
- Causal effect: β₃ = 15 (employment increased by 15 units due to the treatment)
Exercise 8.3: Parallel Trends
You are evaluating a job training programme. You plot employment trends for the treatment and control groups before the programme and see:
- Treatment group: employment increasing by 2% per year
- Control group: employment increasing by 3% per year
- Is the parallel trends assumption violated?
- What does this imply for the DiD estimate?
- What could you do to address this?
Solution:
- Yes – the trends are not parallel (2% vs 3% per year)
- The DiD estimate will be biased (it will pick up the difference in trends, not just the treatment effect)
- Possible solutions: include time trends in the model, use synthetic control, or use event study methods
8.6 Key Terms
Panel Data
Longitudinal Data
Pooled OLS
Fixed Effects (FE)
Random Effects (RE)
Within Estimator
Hausman Test
Difference-in-Differences (DiD)
Treatment Group
Control Group
Parallel Trends Assumption
Causal Inference
Counterfactual
8.7 Further Reading
- Wooldridge, J.M. (2020). Introductory Econometrics: A Modern Approach, Chapter 13 (Pooling Cross-Sections Across Time) and Chapter 14 (Panel Data).
- Stock, J.H. & Watson, M.W. (2019). Introduction to Econometrics, Chapter 10 (Regression with Panel Data) and Chapter 13 (Experiments and Quasi-Experiments).
- Angrist, J.D. & Pischke, J.S. (2015). Mastering 'Metrics, Chapter 5 (Differences-in-Differences).
8.8 What's Next?
In Chapter 9, we will cover Time Series Analysis and Forecasting:
- Stationarity and unit roots
- ARIMA models
- Forecasting methods
- Vector Autoregression (VAR)
→ Proceed to Chapter 9 (Coming Soon)
🔄 Ready to connect with MORISTAT?