π Lecture 35 β Panel Data Methods
π Overview: This lecture introduces panel data, a type of econometric data that tracks the same cross-sectional entities over time. It explains the benefits, drawbacks, and key estimation models for panel data, including pooled regression, fixed effects, and random effects models.
ποΈ Topics Covered
The lecture covers the types of econometric data including time series, cross-sectional, pooled, and panel data, with detailed definitions and examples. It discusses panel data types (short/long, balanced/unbalanced, fixed/rotating), benefits and drawbacks, the rationale for using panel data due to unobserved heterogeneity, and estimation models including pooled regression, Least Square Dummy Variable (LSDV) models, and the error component model distinguishing between fixed and random effects.
π Lecture Summary
Types of Econometric Data
Econometric data can be classified into several types. Time Series Data involves observations at different points in time. Cross Sectional Data involves observations of different entities at the same point in time. Pooled Data is a mixture of time series and cross-sectional data. Panel Data (also called longitudinal data or repeated cross sections) is a specific type of data where the same cross-sectional entities are observed over time.
π Definition β Pooled Data: Randomly sampled cross sections of individuals at different points in time.
π Example of Pooled Data:
| Respondent | Year | Income (Rs.) | Expenditure (Rs.) |
|---|---|---|---|
| Ali | 2012 | 12000 | 9500 |
| Arif | 2012 | 15000 | 11500 |
| Sakina | 2012 | 11500 | 9000 |
| Ali | 2013 | 12500 | 10000 |
| Jameel | 2013 | 11000 | . |
| Fatima | 2013 | 14000 | 12500 |
| Baqir | 2013 | 9500 | 8500 |
In pooled data, individuals may or may not be repeated, there may be different numbers of observations in different time periods, and there may be missing values.
Examples of pooled data include Women's Fertility over time, Population Survey, Labor Force Survey, Marketing Surveys, and Consumer Surveys.
π Definition β Panel Data: Observe cross sections of the same individuals at different points in time.
Examples of panel data include: β’ Panel Survey of Income Dynamics (PSID) β’ British Household Panel Survey (BHPS) β’ US Time Use Surveys β’ French Time Use Surveys β’ German Socio-Economic Panel β’ National Longitudinal Surveys (NLS)
Panel data is also a pooled data set, but not all pooled data should be called panels.
π Panel Dataset Example:
| Country | Year | Y | X |
|---|---|---|---|
| 1 | 2012 | 6 | 9 |
| 1 | 2012 | 3 | 8 |
| 1 | 2012 | 5 | 11 |
| 2 | 2013 | 9 | 12 |
| 2 | 2013 | 5 | 7 |
| 2 | 2013 | 6 | 14 |
| 3 | 2014 | 11 | 14 |
| 3 | 2014 | 6 | 5 |
| 3 | 2014 | 8 | 16 |
Panel data shows the behavior of individual entities across time. The same set of individuals are normally observed, though there may be missing values.
Types of Panel Data
Panel data can be classified into several types.
Short and Long Panel: A Short Panel has many entities but few time periods. A Long Panel has many time periods.
Balanced and Unbalanced Panel: A Balanced Panel has all entities with measurements in all time periods (number of observations = nT). An Unbalanced Panel has missing observations for some entities in some time periods.
Fixed and Rotating Panel: A Fixed Panel has individuals that remain the same. A Rotating Panel (also called Pseudo Panels) has individuals that change over time.
Compact Panel: A Compact Panel has consecutive time periods.
Panel Data Benefits
Panel data offers several advantages:
- More degrees of freedom (nT)
- Captures more complexities (blends both cross-sectional and time series behavior)
- Better forecasts
- We can study heterogeneity and avoid omitted variable bias
Panel Data Drawbacks
Panel data also has drawbacks:
- Data collection issues
- Sampling design and coverage issues
- No response cases in micro panels
- Cross-country correlation in case of macro panels (e.g., location or spatial correlation, gravity models)
- Attrition: dropping out of individuals leads to an unbalanced and/or uncompact panel
Rationale for Using Panel Data
The main rationale for using panel data is Unobserved Heterogeneity. Many individual characteristics are not observed; examples include risk-taking behavior and ability. These vary across individuals and are called unobserved heterogeneity. If they influence the response variable and are correlated to regressors, OLS results will be biased.
π‘ Why this matters: Unobserved heterogeneity is a major source of bias in cross-sectional regressions. Panel data allows us to control for these unobserved, time-invariant characteristics.
Examples of Unobserved Heterogeneity: β’ Returns to Education: Ability is not observed; returns may be influenced due to ability β’ Discrimination: Race, Gender, Religion β’ Unobserved characteristics of groups: Attitude to risk, Social behavior, Working habits β’ Macro Panels (e.g., country GDP): Countries have some unobserved characteristics
Pooled Regression
If we ignore the panel structure of the model and just run a regression, it is called a pooled regression or regression on pooled data. We have to assume that the error is ( e_{it} \sim N(0, \sigma^2) ), which may not be the case. We can pool the data with or without constraints on the disturbance term. We can use the Chow test (discussed with Stata) to test whether pooling is appropriate.
Least Square Dummy Variable Model
Dummy Variables can be used for different individual or time entities or both. Regression could be run using the dummy variables on the RHS of the regression equation. We can capture different intercepts for different groups. Problems include lack of degrees of freedom or the dummy variable trap.
Error Component: One Way and Two Way
Consider the model with ( e_{it} = \mu_i + u_{it} ).
Fixed Effect: When we assume ( \mu_i ) to be constant (for one individual, different for different individuals).
Random Effect: When we assume ( \mu_i ) is drawn independently from some probability distribution.
β Key Takeaways
Panel data tracks the same entities over time, allowing researchers to control for unobserved heterogeneity that would bias OLS in cross-sectional regressions. The key advantage is the ability to study individual-specific characteristics that are time-invariant and unobserved, such as ability or risk attitude. Panel data estimation models include pooled regression (which ignores the panel structure), Least Square Dummy Variable (LSDV) models (which use dummy variables for entities), and error component models. The error component model splits the error term into an individual-specific component (( \mu_i )) and an idiosyncratic component (( u_{it} )), with fixed effects treating ( \mu_i ) as constant and random effects treating it as randomly drawn from a distribution.
π§ Quick Revision Questions
- What is the key difference between pooled data and panel data?
- What is unobserved heterogeneity and why does it cause bias in OLS?
- What are the three types of panel data classifications discussed in the lecture?
- What is attrition in the context of panel data and what problem does it cause?
- What is the difference between fixed effects and random effects in the error component model?
π Lecture 36 β Panel Data Models-II
π Overview: This lecture continues the discussion of panel data models, focusing on the Fixed Effect Model and Random Effect Model. It explains how to handle unobserved heterogeneity across entities, provides estimation methods like first differencing and deviations from means, introduces the random effects approach, and demonstrates practical implementation in Stata. This is critical for understanding how to analyze longitudinal data and choose the appropriate model for causal inference.
ποΈ Topics Covered
The lecture begins by revisiting the Fixed Effect Model with a composite error term, showing how unobserved heterogeneity becomes part of the intercept. It then covers two estimation methods for fixed effects: first differencing and deviations from means (within estimator). The Random Effect Model is introduced, assuming heterogeneity is uncorrelated with regressors. Finally, Stata implementation is demonstrated, including setting panel data, summary statistics, plotting, and model estimation with the Hausman test.
π Lecture Summary
Fixed Effect Model
Consider the model Yα΅’β = Ξ²β + Ξ²βXβα΅’β + Ξ²βXβα΅’β + eα΅’β, with eα΅’β = ΞΌα΅’ + uα΅’β. Then Yα΅’β = (Ξ²β + ΞΌα΅’) + Ξ²βXβα΅’β + Ξ²βXβα΅’β + uα΅’β. The unobserved heterogeneity ΞΌα΅’ is now part of the constant term but is different for different individuals. Individuals have different intercepts but common slopes. A diagram shows three different classes with three different intercepts but a common slope, which is the concept in the fixed effect model.
π Definition β Fixed Effect Model: A panel data model that allows each entity (individual, firm, country) to have its own intercept, capturing time-invariant unobserved heterogeneity, while slopes are common across entities.
π Formula: Yα΅’β = (Ξ²β + ΞΌα΅’) + Ξ²βXβα΅’β + Ξ²βXβα΅’β + uα΅’β β The intercept is entity-specific (Ξ²β + ΞΌα΅’), but the effect of X on Y is the same for all entities.
π Example: If studying GDP of Pakistan, India, and Sri Lanka over time, each country gets its own intercept to account for unobserved time-invariant characteristics like geography or culture, while the effect of investment (gfcf) on GDP is assumed the same across countries.
Fixed Effect Model Estimation: First Difference
Eliminating unobserved heterogeneity by first differencing. Starting from Yα΅’β = (Ξ²β + ΞΌα΅’) + Ξ²βXβα΅’β + Ξ²βXβα΅’β + uα΅’β, take the model with one time lag: Yα΅’βββ = (Ξ²β + ΞΌα΅’) + Ξ²βXβα΅’βββ + Ξ²βXβα΅’βββ + uα΅’βββ. Subtract: Yα΅’β β Yα΅’βββ = Ξ²β(Xβα΅’β β Xβα΅’βββ) + Ξ²β(Xβα΅’β β Xβα΅’βββ) + (uα΅’β β uα΅’βββ). This gives ΞYα΅’β = Ξ²βΞXβα΅’β + Ξ²βΞXβα΅’β + Ξuα΅’β. This can be generalized for more variables and works fine for two time periods.
π Definition β First Difference Estimator: A method that eliminates unobserved fixed effects by subtracting the previous time period from the current time period for each entity, removing the entity-specific intercept.
π Formula: ΞYα΅’β = Ξ²βΞXβα΅’β + Ξ²βΞXβα΅’β + Ξuα΅’β β Changes in Y are modeled as a function of changes in X, with the fixed effect ΞΌα΅’ differenced out.
Fixed Effect Model Estimation: Deviation from Means (Alternative Approach)
We can use the deviations from means. Starting from Yα΅’β = (Ξ²β + ΞΌα΅’) + Ξ²βXβα΅’β + Ξ²βXβα΅’β + uα΅’β, taking deviations from mean eliminates the intercept: Yα΅’β β Θ²α΅’. = Ξ²β(Xβα΅’β β XΜβα΅’.) + Ξ²β(Xβα΅’β β XΜβα΅’.) + uα΅’β. The constant part is eliminated. Deviations from mean for each individual, averaged across all time periods. The model can be estimated by OLS, LSDV, etc. This is called the βwithinβ estimator. The βbetweenβ estimator can be found by using the individual averages. The βoverall estimatorβ is the weighted average of within and between estimators.
π Definition β Within Estimator: The fixed effect estimator obtained by regressing the deviations of Y from its entity-specific mean on the deviations of X from their entity-specific means, eliminating all time-invariant heterogeneity.
Random Effect Model
If correct weights are used, the combination of fixed (within) and between effect estimators is called the random effect estimator. The model is Yα΅’β = Ξ²β + Ξ²βXβα΅’β + Ξ²βXβα΅’β + eα΅’β, with eα΅’β = ΞΌα΅’ + uα΅’β. When we assume ΞΌα΅’ is drawn independently from some probability distribution, we are dealing with the random effect model. When unobserved heterogeneity is uncorrelated with regressors, panel data techniques are not needed to produce a consistent estimator. We must correct for serial correlation between observations of the same entity. If E(Xα΅’β, eα΅’β) β 0, the Fixed Effect model may be used. When E(Xα΅’β, eα΅’β) = 0, the Random Effect model may be used to overcome the serial correlation of panel data.
To estimate the random effect model, we assume ΞΌα΅’ is part of the error term eα΅’β. We evaluate the structure of the error and apply appropriate Generalized Least Squares (with correct weights) to calculate efficient estimators. The following assumptions must hold:
- E(ΞΌα΅’) = E(uα΅’β) = 0
- E(uΒ²α΅’β) = ΟΒ²α΅€ and E(ΞΌΒ²α΅’) = ΟΒ²ΞΌ
- E(uα΅’β, ΞΌα΅’) = 0 for all i and t
- E(eΒ²α΅’β) = ΟΒ²α΅€ + ΟΒ²ΞΌ
- E(Xβα΅’β, ΞΌα΅’) = 0 for all k, i, and t
π Definition β Random Effect Model: A panel data model that treats unobserved heterogeneity as a random variable uncorrelated with the regressors, allowing the use of GLS to produce efficient estimates while correcting for serial correlation.
π‘ Why this matters: The choice between fixed and random effects depends on whether unobserved heterogeneity is correlated with the regressors (use FE) or not (use RE). The Hausman test formally tests this assumption.
Panel Data Models using Stata
All panel data commands start with xt. We need to set the panel data first using xtset. If needed, we need to reshape our panel. The example uses a file panel1.dta with data from World Development Indicators for Pakistan, India, and Sri Lanka from 1991 to 2012 β a strongly balanced long panel.
The xtset command sets the data as panel data where both variables of cross-sectional and time should be numeric. Country is a string variable, so we create a numeric ID using: encode country, generate(countryId).
The xtsummarize command provides summary statistics specific to panel data.
π‘ Why this matters: Properly setting panel data in Stata ensures that subsequent commands correctly account for the panel structure of the data.
xtline and Exploring Data
Consider that GDP is a function of gfcf (gross fixed capital formation), exports, and imports. The xtline gdp command plots the dependent variable by country over time, showing individual trends for each entity.
Fixed Effects in Stata
Use fixed-effects (FE) whenever you are only interested in analyzing the impact of variables that vary over time. FE explores the relationship between predictor and outcome variables within an entity (country, person, company). Each entity has its own individual characteristics that may or may not influence the predictor variables (e.g., being male or female could influence opinion, or political system could affect trade or GDP, or business practices could influence stock price).
When using FE, we assume that something within the individual may impact or bias the predictor or outcome variables, and we need to control for this. This is the rationale for the assumption of correlation between entityβs error term and predictor variables. FE removes the effect of those time-invariant characteristics from the predictor variables so we can assess the predictorsβ net effect.
Least Square Dummy Variable (LSDV) model includes dummy variables for each entity to capture fixed effects. Another important assumption is that those time-invariant characteristics are unique to the individual and should not be correlated with other individual characteristics. If the error terms are correlated, FE is not suitable, and modeling that relationship (probably using random-effects) is needed β this is the main rationale for the Hausman test.
Random Effect Model in Stata
The random effect model is specified as Yα΅’β = Ξ²β + Ξ²βXβα΅’β + Ξ²βXβα΅’β + eα΅’β, where Y = gdp, Xβ = gfcf, Xβ = exports, and eα΅’β = ΞΌα΅’ + uα΅’β. In Stata, the xtreg command with the re option estimates the random effects model.
Fixed or Random? Hausman Test
The Hausman test helps decide between fixed and random effects. The procedure is:
qui xtreg gdp gfcf exports, feβ estimate fixed effects modelestimates store fixedβ store the resultsqui xtreg gdp gfcf exports, reβ estimate random effects modelestimates store randomβ store the resultshausman fixed randomβ perform the test
Rejecting Hβ (the null hypothesis that random effects are consistent) means that fixed effects should be used.
π Definition β Hausman Test: A statistical test that compares fixed effects and random effects estimates to determine whether the unobserved heterogeneity is correlated with the regressors. The null hypothesis is that random effects are consistent and efficient.
π‘ Why this matters: Using the wrong model (e.g., RE when FE is required) leads to inconsistent estimates. The Hausman test provides an objective criterion for model selection in panel data analysis.
β Key Takeaways
The Fixed Effect Model accounts for unobserved time-invariant heterogeneity by allowing each entity to have its own intercept, estimated via first differencing or the within estimator (deviations from means). The Random Effect Model treats heterogeneity as random and uncorrelated with regressors, requiring GLS for efficient estimation while correcting for serial correlation. The key decision between FE and RE depends on whether E(Xα΅’β, ΞΌα΅’) = 0; the Hausman test formally tests this assumption, with rejection favoring the fixed effects model. In Stata, panel data must be set using xtset, and commands like xtreg with fe or re options implement the models. Understanding these models is essential for correctly analyzing longitudinal data and drawing valid causal inferences.
π§ Quick Revision Questions
- What is the key difference between the Fixed Effect Model and the Random Effect Model in terms of how they treat unobserved heterogeneity (ΞΌα΅’)?
- How does the first difference estimator eliminate the fixed effect ΞΌα΅’? Write the resulting equation.
- What is the within estimator and how does it differ from the between estimator in panel data?
- State the null hypothesis of the Hausman test and explain what rejecting Hβ implies for model selection.
- Given panel data with E(Xα΅’β, ΞΌα΅’) β 0, which model (FE or RE) is appropriate and why?
π Lecture 37 β Panel Data Methods & Post Estimation Tests
π Overview: This lecture covers the complete procedure for panel data analysis in Stata, focusing on fixed and random effects estimation and the battery of post-estimation diagnostic tests required to validate model assumptions. It demonstrates how to test for time fixed effects, choose between fixed and random effects using the Hausman test, and diagnose problems like heteroskedasticity and serial correlation, along with their remedies.
ποΈ Topics Covered
The lecture begins with fixed effect estimation and testing for time fixed effects using joint significance tests on year dummies. It then covers the Hausman test to choose between fixed and random effects, the Breusch-Pagan LM test to decide between random effects and pooled OLS, tests for cross-sectional correlation in fixed effects models, the modified Wald test for groupwise heteroskedasticity, and Wooldridgeβs test for serial correlation. Remedies including robust standard errors, xtregar for AR(1) errors, and cluster-robust standard errors are demonstrated using both the nlswork and grunfeld datasets.
π Lecture Summary
Fixed Effect Estimation
Fixed effects models control for time-invariant unobserved heterogeneity across entities (e.g., individuals, companies) by allowing each entity to have its own intercept. In Stata, the command xtreg with the fe option estimates the within-panel fixed effects model. The lecture uses nlswork data with dependent variable ln_wage and independent variables tenure, age, south, and union.
π Definition β Fixed Effects (FE) Model: A panel data model that controls for time-invariant unobserved characteristics by focusing on within-entity variation over time. Each entity has its own constant term that captures all time-stable attributes.
π Formula: xtreg ln_wage tenure age south union, fe β estimates the within-panel fixed effects regression.
π Example: Using webuse nlswork, clear then running xtreg ln_wage tenure age south union, fe estimates how changes in tenure, age, and union status affect wage changes within each individual worker over time.
Testing Time Fixed Effects
Time fixed effects account for unobserved time-specific shocks that affect all entities equally (e.g., macroeconomic conditions, policy changes). The test checks whether all year dummy coefficients are jointly equal to zero. In Stata, include i.year in the model and use testparm i.year after estimation.
π Definition β Time Fixed Effects: Dummy variables for each time period that capture common shocks across all entities in that period.
π Formula: xtreg ln_wage tenure age south union i.year, fe followed by testparm i.year
π‘ Why this matters: If time fixed effects are jointly significant, ignoring them can bias coefficient estimates. The test result in the nlswork example showed rejection of the null (all year coefficients zero), meaning time dummies are needed.
Testing for Fixed Effects: Hausman test
The Hausman test formally compares fixed effects and random effects estimators to determine which model is appropriate. The null hypothesis is that the random effects model is correct (i.e., individual effects are uncorrelated with regressors). A significant test statistic indicates that random effects are inconsistent, so fixed effects is preferred.
π Definition β Hausman Test: A specification test that checks whether the unique errors (entity-specific effects) are correlated with the regressors. If correlated, FE is consistent and RE is inconsistent.
π Formula:
xtreg ln_wage tenure age south union, fe
estimates store fixed
xtreg ln_wage tenure age south union, re
estimates store random
hausman fixed random
π Example: For the nlswork data, the Hausman test rejects the null (Hβ rejected), indicating that the fixed effect model is better than random effects.
Testing for Random Effects: LM test (Breusch and Pagan LM test for random effects)
The Breusch-Pagan Lagrange Multiplier (LM) test helps decide between a random effects regression and a simple OLS regression (pooled model). The null hypothesis is that variances across entities is zero β meaning no significant difference across units (no panel effect).
π Definition β BP-LM Test: A test for the presence of random effects. If the null is not rejected, simple OLS (pooled regression) is appropriate.
π Formula:
xtreg ln_wage tenure age south union, re
xttest0
π Example: After running the random effects model, xttest0 gave a result where we fail to reject the null, meaning no random effects exist and simple OLS can be run instead.
Breusch-Pagan LM test for cross-sectional correlation in fixed effects model
This test checks for cross-sectional dependence (contemporaneous correlation) in the residuals of a fixed effect regression model. This is particularly problematic in macro panels with long time series (T > N). The null hypothesis is that residuals across entities are not correlated.
π Definition β Cross-Sectional Dependence Test (xttest2): Tests whether residuals from different entities are correlated with each other in the same time period.
π Formula:
xtreg ln_wage tenure age south union in 1/25, fe
xttest2
π Example: Using only the first 25 observations to address the macro panel problem, the test accepted Hβ, indicating no cross-sectional correlations found.
Testing for Heteroskedasticity
The modified Wald statistic tests for groupwise heteroskedasticity in the fixed effects model. The null hypothesis is homoskedasticity (constant variance of errors across groups/entities).
π Definition β Modified Wald Test (xttest3): A test for groupwise heteroskedasticity in panel data fixed effects models.
π Formula:
xtreg ln_wage tenure age south union, fe
xttest3
π Example: In the nlswork example, the test indicated heteroskedasticity exists. The conclusion is to use the robust option with regression for both fixed and random effects models.
Testing for Serial Correlation: Wooldridge test
The Wooldridge test for serial correlation checks whether the idiosyncratic errors in a linear panel-data model are serially correlated. The null hypothesis is no serial correlation.
π Definition β Wooldridge Test (xtserial): A test for first-order serial correlation in the errors of panel data models.
π Formula: xtserial ln_wage tenure age south union
π Example: The test concluded that serial correlation exists. The remedy is to use xtregar.
Remedy for Serial Correlation: xtregar
xtregar fits regression models for panel data when the residual is first-order autoregressive (AR(1)). It offers a within estimator for fixed-effects models and a GLS estimator for random-effects models.
π Definition β xtregar: Panel data regression with AR(1) disturbances, handling both fixed and random effects specifications.
π Formula:
- Fixed-effects:
xtregar ln_wage tenure age south union, fe - Random-effects:
xtregar ln_wage tenure age south union, re
π Example: Since serial correlation exists in the nlswork example, xtregar ln_wage tenure age south union, fe was used to correct for AR(1) errors.
Example of Panel Data using grunfeld.dta
The lecture demonstrates a complete panel data workflow using the classic Grunfeld investment data, where company is the entity and year is the time variable.
π Example: The full procedure includes:
- Load data:
webuse grunfeld, clearthenxtset company year - Run FE:
xtreg invest mvalue kstock, fe - Test time FEs:
qui xtreg invest mvalue kstock i.year, fethentestparm i.yearβ p-value > 5%, so accept Hβ β no time FEs needed - Test for random effects:
qui xtreg invest mvalue kstock, rethenxttest0β reject Hβ, panel effects exist - Hausman test: The test shows random effect model seems appropriate (RE preferred over FE)
- Heteroskedasticity:
xttest3β reject Hβ, heteroskedasticity exists, use robust option (e.g.,xtreg invest mvalue kstock, fe robust) - Serial correlation:
xtserial invest mvalue kstockβ reject Hβ, serial correlation exists, usextregar - Remedy:
xtregar invest mvalue kstock, feandxtregar invest mvalue kstock, reβ RE results shown
Panel Data: both HSK and SC!
When both heteroskedasticity and serial correlation exist simultaneously, use cluster-robust standard errors with the entity ID variable as the cluster input.
π Definition β Cluster-Robust Standard Errors: Standard errors that are robust to both heteroskedasticity and arbitrary within-cluster serial correlation.
π Formula: xtreg invest mvalue kstock, fe cluster (company)
π Example: Using the cluster(company) option with xtreg produces standard errors that are completely robust to any kind of serial correlation and/or heteroskedasticity.
β Key Takeaways
The panel data workflow requires sequential diagnostic testing after initial estimation: first test if time fixed effects are needed using testparm i.year, then decide between FE and RE using the Hausman test, and check whether panel effects exist at all using the Breusch-Pagan LM test. Post-estimation, test for heteroskedasticity using xttest3 (modified Wald test), for cross-sectional dependence using xttest2 in macro panels, and for serial correlation using xtserial. The remedy for serial correlation alone is xtregar, while the most robust solution for both heteroskedasticity and serial correlation is to use cluster-robust standard errors with the entity ID in the cluster() option.
π§ Quick Revision Questions
- What command sequence tests whether time fixed effects are jointly significant, and what is the null hypothesis?
- How does the Hausman test determine whether fixed effects or random effects is the correct model?
- What does the Breusch-Pagan LM test (xttest0) help you decide between, and what does rejecting the null imply?
- What is the Stata command to test for groupwise heteroskedasticity in a fixed effects model, and what is the recommended remedy if heteroskedasticity is found?
- When both heteroskedasticity and serial correlation are present, what single Stata option provides robust inference?
π Lecture 38 β Qualitative and limited dependent variable models-I (Categorical dependent variable models)
π Overview: This lecture introduces categorical dependent variable models, focusing on situations where the outcome variable is qualitative rather than continuous. It explains why Ordinary Least Squares (OLS) is inappropriate for such data and presents logistic regression as the primary solution, covering binary, ordinal, and multinomial logistic regression models with their Stata implementations.
ποΈ Topics Covered
This lecture covers the concept of categorical variables and why OLS fails for them, the fundamentals of logistic regression including the logistic function and log of odds, interpretation of odds ratios, binary logistic regression in Stata with output interpretation, pseudo R-squared measures, ordinal logistic regression for ordered categories, and multinomial logistic regression for nominal categories without natural order.
π Lecture Summary
Variables with category
Categorical variables are variables that have categories and are normally qualitative in nature. They can be binary (two categories), multivariate (multiple categories), and can be ordinal (natural order exists) or nominal (no order). Examples include gender, color of eyes, educational status, and different outcomes of an event encoded in numbers. When the dependent variable is categorical, OLS is biased and inefficient because it violates key assumptions like normality and linearity.
Logistic Regression
Logistic regression is a type of regression analysis used to predict the outcome of a categorical variable (binary or others). The dependent variable has a limited number of outcomes and is predicted using a logistic function. Unlike OLS, logistic regression does not make any assumptions of normality, linearity, and homogeneity of variance for the independent variables. The minimum number of cases per independent variable is 10.
π Definition β Logistic Function: F(t) = e^t / (e^t + 1) = 1 / (1 + e^(-t)) Where t is a linear function of the explanatory variables.
π Formula for probability of success: Ο(x) = 1 / (1 + e^(-(Ξ²β + Ξ²βX))) This can be interpreted as the probability of the dependent variable equaling a 'success' or a 'case'.
π Formula for log of odds (logit): g(x) = ln[Ο(x) / (1 - Ο(x)] = Ξ²β + Ξ²βX This is the natural logarithm of the odds.
The logistic function also has an equivalent formulation as a latent variable model. Let Y* be a continuous latent variable (unobserved random variable) where Y* = Ξ²βX + Ξ΅, and Ξ΅ ~ Logistic(0,1).
π Definition β Odds Ratio: The ratio of probability of an event occurring to probability of an event not occurring. It measures the association between exposure and outcome.
Commands for logistic regression in Stata
- Binary logit:
logit - Ordered logit:
ologit - Multinomial logit:
mlogit
The syntax of the logit command is: logit depvar [indepvars] [if] [in] [weight] [, options]
Menu: Statistics > Binary outcomes > Logistic regression
Interpreting Results
In binary logistic regression, odds mean the ratio of favorable items to non-favorable items. The interpretation is: The log of odds changes by the amount of the coefficient for one unit increase in the independent variable. Prob > Chi2 = 0.0000 indicates that the model as a whole fits significantly better than an empty model (null model). The output shows coefficients, their standard errors, the z-statistic, associated p-values, and the 95% confidence interval of the coefficients. For example, for one unit increase in GAT score, the log odds of getting CGPA > 3 in Masters increases by 0.1787. If Gender is not significant (p-value > 0.05), it does not have a statistically significant effect on the outcome.
Pseudo Rsquare
Because OLS does not apply to logistic regression, an equivalent statistic to R-squared does not exist. Instead, pseudo R-squares are used because they look like R-squared (range from 0 to 1). Higher values indicate better model fit. Different pseudo R-squared measures can give different values, so caution is needed in interpretation. π‘ Why this matters: Unlike OLS R-squared which measures the proportion of variance explained, pseudo R-squared values cannot be interpreted as variance explained; they are relative measures of model improvement.
To get odds ratios instead of log of odds, use the or option in Stata.
Ordinal Logistic Regression
Ordinal logistic regression is used when the dependent variable is categorical with a natural order. Examples include: encoding in age brackets, educational grades encoded numerically, income brackets, size (small, medium, large, extra large), decision (unlikely, somewhat likely, very likely), and opinion (strongly agree, agree, etc.). The actual numerical values assigned to categories are irrelevantβonly their order matters. Larger values are assumed to correspond to "higher" outcomes.
In Stata: Command Syntax: ologit depvar [indepvars] [if] [in] [weight] [, options]
Menu: Statistics > Ordinal outcomes > Ordered logistic regression
Multinomial Logistic Regression
Multinomial logistic regression is used when there is no order to the categories of the outcome variableβthe categories are nominal. Examples include occupational choice (categories of job) and choice of specialization in degrees (Accounting, Finance, Marketing, etc.). The mlogit command fits maximum-likelihood multinomial logit models, also known as polytomous logistic regression.
In Stata: Menu: Statistics > Categorical outcomes > Multinomial logistic regression
Command Syntax: mlogit depvar [indepvars] [if] [in] [weight] [, options]
β Key Takeaways
When the dependent variable is categorical, OLS is biased and inefficient, making logistic regression the appropriate alternative. Logistic regression uses a logistic function to model probabilities and can handle binary, ordinal, and nominal outcomes. The logit is the natural log of odds, and coefficients represent the change in log odds per unit increase in the independent variable. Stata provides three main commands: logit for binary, ologit for ordered, and mlogit for multinomial outcomes. Pseudo R-squared values provide a rough measure of model fit but should not be interpreted like OLS R-squared.
π§ Quick Revision Questions
- Why is OLS biased and inefficient when the dependent variable is categorical?
- Write the logistic function formula and explain what it represents.
- What does the log of odds (logit) formula represent, and how is it interpreted in terms of coefficients?
- When should you use ordinal logistic regression versus multinomial logistic regression?
- What does a Prob > Chi2 value of 0.0000 indicate in logistic regression output?
π Lecture 39 β Qualitative and limited dependent variable models-II (Categorical dependent variable models)
π Overview: This lecture extends the discussion of categorical dependent variable models by introducing Probit Regression as an alternative to Logit. It covers the probit function, interpretation of coefficients, and Stata implementation for binary, ordinal, and multinomial probit models. Understanding this material is critical for modeling scenarios where the dependent variable takes discrete values (e.g., yes/no, ordered categories, or nominal choices).
ποΈ Topics Covered
The lecture begins with the definition and mechanics of Probit Regression, including the probit function based on the standard normal distribution. It explains how to interpret probit coefficients (changes in Z-scores, not marginal effects), presents an example of binary probit using Stata, and covers post-estimation tests. The lecture then moves to Ordinal Probit Regression for ordered categorical outcomes and concludes with Multinomial Probit Regression for nominal categorical outcomes, including Stata syntax and examples.
π Lecture Summary
Probit Regression
A type of regression analysis used to predict the probability of a categorical variable (binary or others). Examples of categorical variables are the same as in logit. The dependent variable has a limited number of outcomes. The dependent variable is predicted by using a probit function. The minimum number of cases per independent variable is 10.
π Definition β Probit Function: Recall the standard normal distribution and Z-scores. Given any Z-score, ΙΈ(Z) is the cumulative normal distribution function. For any given Z, ΙΈ(Z) β [0,1].
π Formula: Y = ΙΈ(XΞ² + Ξ΅), then ΙΈβ»ΒΉ(Y) = XΞ² + Ξ΅. F(Y) = ΙΈβ»ΒΉ(Y) is called the probit function.
π Definition β Probit: Probit may be short for "probability unit." P(Y)=1.
π‘ Why this matters: XΞ² is the Z-value of a normal distribution. Higher the estimation value, more likely is the event to happen. A one unit change in the value of X brings Ξ² change in the Z-score of Y. The estimated curve is S-shaped.
π Example: The lecture shows a graph where red dots represent actual values of the categorical variable ('CGPA>3' = 1), and the curve shows the probit fit.
Binary probit command in Stata: probit
Syntax: probit depvar [indepvars] [if] [in] [weight] [, options]
Menu: Statistics > Binary outcomes > Probit regression
Consider the file logitProbit.dta. Run the Binary Probit regression.
Interpreting Results:
- Significance is almost as in logit.
- Model, as a whole is statistically significant (Pr > chi2) < 0.05.
- Coefficients: Change in Z-score or probit due to change in one unit of independent variable (they are less than one).
Interpretation of the coefficients:
- Not as in OLS.
- Not slope coefficient or marginal effects.
- The increase in probability due to a one-unit increase in a given independent variable/predictor depends both on the values of the other predictors and the starting value of the given predictors (different for different rows of observation).
- The predicted probability of CGPA>3 can be calculated as F(Ξ²β + Ξ²βGAT + Ξ²βAGE + Ξ²βHRS), where Ξ²α΅’ are the coefficients generated by the probit regression.
- Effect of change in one variable on the probability of getting CGPA>3 depends on the current value of a variable under consideration and also on the GIVEN/CONSTANT values of the other variables.
Tests after probit (fitness, different pseudo R squares): If fitstat is not installed, try ssc install fitstat.
Ordinal Probit Regression
Ordinal categorical dependent variable examples:
- Encoding in age brackets
- Educational Grades (encoded numerically)
- Income brackets encoded numerically
- Size (small, medium, large, or extra large)
- Decision (unlikely, somewhat likely, or very likely)
- Opinion (strongly agree, agree, etc.)
- The actual values are irrelevant.
- Larger values are assumed to correspond to "higher" outcomes.
In Stata:
Menu: Statistics > Ordinal outcomes > Ordered probit regression
Command Syntax: oprobit depvar [indepvars] [if] [in] [weight] [, options]
Magnitude of Coefficients differs from probit by a scale factor. Magnitude of Coefficients is not interpreted. The sign will matter.
Multinomial Probit Regression
No order to the categories of the outcome variable is found (i.e., the categories are nominal).
Examples:
- Occupational choice (categories of job)
- Choice of specialization in Degrees (Accounting, Finance, Marketing, etc.)
π Definition β mprobit: Fits maximum-likelihood multinomial probit models, also known as polytomous probit regression.
In Stata:
Menu: Statistics > Categorical outcomes > Independent multinomial probit
Command Syntax: mprobit depvar [indepvars] [if] [in] [weight], [options]
β Key Takeaways
Probit regression uses the cumulative standard normal distribution function to model the probability of categorical outcomes, with coefficients representing changes in Z-scores rather than direct probability changes. Unlike OLS, probit coefficients are not marginal effects; the impact on probability depends on the values of all predictors. The lecture covers three types: binary probit (for dichotomous outcomes), ordinal probit (for ordered categories where actual values are irrelevant but larger values correspond to higher outcomes), and multinomial probit (for nominal categories with no order). In Stata, the commands are probit, oprobit, and mprobit respectively, with post-estimation tests available via fitstat. The key distinction from logit is the use of the normal distribution instead of the logistic distribution.
π§ Quick Revision Questions
- What function does probit regression use to transform the linear predictor into a probability?
- How do you interpret a probit coefficient for a one-unit change in an independent variable?
- What is the difference between ordinal probit and multinomial probit in terms of the dependent variable?
- In Stata, what command would you use to run an ordered probit regression?
- Why can't probit coefficients be interpreted as marginal effects like in OLS regression?
π Lecture 40 β Qualitative and limited dependent variable models-III & Censored Regression Models (Tobit Model)
π Overview: This lecture continues the discussion of qualitative and limited dependent variable models, covering the relationship between probability and odds ratio, marginal effects in probit models, and tests after logit/probit models such as the likelihood ratio test and Wald test. It then introduces censored regression models, specifically the Tobit model, for situations where the dependent variable is incompletely observed, and demonstrates its implementation in Stata.
ποΈ Topics Covered
The lecture first maps the relationship between probability, odds ratio, and log-odds, then explains how marginal effects are calculated in probit models and implemented in Stata. It covers the likelihood ratio test and Wald test for model comparison and joint significance testing. The second half introduces truncated versus censored data, the structure of the Tobit model for latent variables censored at a threshold, and its application using Stata including interpretation of output.
π Lecture Summary
Probability Vs. Odd Ratio
The lecture presents a table mapping the relationship between probability, odds ratio, and log-odds (ln odds). Probability ranges from 0 to 1, odds ratio ranges from 0 to β, and log-odds ranges from ββ to β. When probability = 1/2, odds ratio = 1 and log-odds = 0 (even odds). When probability > 1/2, odds ratio > 1 and log-odds is positive (favor). When probability < 1/2, odds ratio < 1 and log-odds is negative (against).
π Definition β Odds Ratio: The ratio of the probability of an event occurring to the probability of it not occurring. Formula: Odds Ratio = Probability of x / (1 β Probability of x).
π Formula: Probability = Odds Ratio / (1 + Odds Ratio) β This converts odds back to probability.
π Example: If probability = 1/3, then odds ratio = (1/3) / (2/3) = 1/2 (against, 1 to 2). If probability = 2/3, then odds ratio = (2/3) / (1/3) = 2 (favor, 2 to 1).
π‘ Why this matters: The coefficients from logit/probit models represent the change in probability or odds ratios, not the probability or odds themselves. The formulas above apply to the variables, not the coefficients.
Marginal Effects
In probit models, the slope (marginal effect) is not simply the coefficient as in OLS. The marginal effect of a predictor on the probability that Y=1 depends on both the values of other predictors and the starting value of the predictor itself.
π Formula: ββ(Yα΅’ = 1 | Xβα΅’, ..., Xβα΅’; Ξ²β, ..., Ξ²β) / βXβα΅’ = Ξ²β Γ ΙΈ(Ξ²β + ΣββXβα΅’)
Here, ΙΈ(Β·) is the standard normal probability density function. The increase in probability due to a one-unit increase in a predictor depends on all other predictors and the starting value of the given predictor β it differs for different rows of observations.
π Definition β Marginal Effects in Stata: Using the command margins, dydx(*) after a probit regression calculates the average marginal effect.
π Example: With file logitProbit.dta, after probit cgpm3 gat age hrs gender, running margins, dydx(*) shows that one unit increase in gat increases the probability of CGPA>3 by 0.0128985.
Tests after logit/probit models
Likelihood ratio test is used for both logit and probit models. It estimates two models (e.g., empty vs. full, or restricted vs. unrestricted) and compares them. The test statistic is distributed chi-squared with degrees of freedom equal to the difference in degrees of freedom between the two models. Significance means the model improves.
π Example: In Stata, run probit cgpm3 (empty model), store as m1, then probit cgpm3 gat age hrs gender (full model), store as m2, then lrtest m1 m2. If the p-value is less than 0.01, including all variables together improves the model. This test is used when the first model is nested in the second.
Wald test estimates similarly but is better as it requires running only one model. It tests if the parameters of interest are jointly equal to zero.
π Example: In Stata, after probit cgpm3 gat age hrs, run test gat age hrs. If the result shows Hβ is rejected at 10%, all coefficients of variables (gat, age, hrs) are not jointly zero.
Censored Data Regression Models: The Tobit Model
OLS is inefficient when the dependent variable is incompletely observed or when the dependent variable is observed completely but the selected sample is not representative of the population.
Truncated Data: Observations on both dependent and independent variables are lost. Example: only small firms included, low income respondents only.
Censored Data: Observations on the dependent variable only are lost (or limited). Examples: income top-coded to 50,000; time bottom-coded to 10-minute chunks.
Tobit Model: Structure Suppose y* is a latent variable that is observed partially for values greater than ΞΈ.
π Formula: y*α΅’ = Xα΅’Ξ² + Ξ΅α΅’, where Ξ΅α΅’ ~ N(0, ΟΒ²)
The observed y is defined as: y = y* if y* > ΞΈ y = ΞΈ if y* β€ ΞΈ
Since data is often censored at zero, the model becomes: y = y* if y* > 0 y = 0 if y* β€ 0
π Examples where Tobit model may be applied:
- Time use surveys: 10-minute time chunks
- Glucometers: reading "Error" or not more than a specific value (e.g., 500 mg/dL)
- GAT: students answering all 100 questions may have different IQ levels and/or aptitude
Tobit Model using Stata
Tobit Model Stata Command: tobit
Syntax: tobit depvar [indepvars] [if] [in] [weight] , ll[(#)] ul[(#)] [options]
Menu: Statistics > Linear models and related > Censored regression > Tobit regression
π Example: Using file logitProbit.dta with variable gat. For left censoring at 60, use tobit gat age hrs gender, ll(60). If there are 40 observations with 10 having gat < 60, even after censoring there are 40 observations. Both left and right censoring can be used.
Interpreting Tobit Output:
- P-value of Chi2: Good fit; at least one regression coefficient is non-zero
- Log likelihood: Used for LR test
- McFadden Pseudo R-square: Model fit measure
- Observation Summary: Shows how many values have been censored (e.g., right censored 12 considered as having 75 marks)
- Regression Coefficients: e.g., age β higher the age, greater the GAT score; one year increase in age may increase GAT score by 3.2 on average
- P-values: Show significance of coefficients
- Estimated standard error of the regression: Like RMSE in OLS
β Key Takeaways
Probability and odds ratio are related by simple formulas, but coefficients from logit/probit models represent changes in probability, not the probability itself. Marginal effects in probit models depend on the values of all predictors and vary across observations, so Stata's margins, dydx(*) command is essential. The likelihood ratio test and Wald test are both used to assess model fit and joint significance, with the Wald test requiring only one model. The Tobit model is necessary when the dependent variable is censored (partially observed), such as top-coded income or time chunks, and OLS would be inefficient for such data.
π§ Quick Revision Questions
- If the odds ratio is 3, what is the corresponding probability?
- Why do marginal effects in probit models differ across observations?
- What is the key difference between the likelihood ratio test and the Wald test in terms of number of models required?
- In the Tobit model, when y* β€ ΞΈ, what value does the observed y take?
- What does the McFadden Pseudo R-square in Tobit output represent?