📚 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:

8.1 What is Panel Data?

Panel data (also called longitudinal data) combines both:

Example: Data on 100 firms over 10 years (100 × 10 = 1,000 observations).

Panel data notation:

Yit = β₀ + β₁Xit + uit

8.1.1 Advantages of Panel Data

8.2 Panel Data Models

8.2.1 Pooled OLS

Ignore the panel structure and treat all observations as independent:

Yit = β₀ + β₁Xit + uit

8.2.2 Fixed Effects (FE)

Allow each individual to have its own intercept (captures time-invariant unobserved heterogeneity):

Yit = β₀ + β₁Xit + αi + uit

8.2.3 Random Effects (RE)

Assume αi is random and uncorrelated with Xit:

Yit = β₀ + β₁Xit + νi + uit

8.2.4 Hausman Test

Tests whether FE or RE is appropriate:

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.

8.3.2 The DiD Model

Yit = β₀ + β₁ × Treati + β₂ × Postt + β₃ × (Treati × Postt) + uit

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.

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.

  1. If unobserved country-specific factors (e.g., culture, institutions) are correlated with trade openness, which method would you use?
  2. If these factors are uncorrelated with trade openness, which method would you use?
  3. 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)
  1. What is the employment level in the control group before the treatment?
  2. What is the employment level in the treatment group before the treatment?
  3. 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:

  1. Is the parallel trends assumption violated?
  2. What does this imply for the DiD estimate?
  3. 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

8.8 What's Next?

In Chapter 9, we will cover Time Series Analysis and Forecasting:

→ Proceed to Chapter 9 (Coming Soon)

🔄 Ready to connect with MORISTAT?