Lecrae

Stata Panel Data

If experience barely changes for any worker, FE estimates will be imprecise. Check within variation via xtsum.

regress gdp fdi trade gcf

Output (illustrative):

| Variable | Coef. | Std. Err. | t | P>|t| | |----------|-------|-----------|----|----| | fdi | 0.142 | 0.021 | 6.76 | 0.000 | | trade | 0.009 | 0.003 | 3.12 | 0.002 | | gcf | 0.047 | 0.011 | 4.27 | 0.000 | | _cons | 6.123 | 0.215 | 28.48 | 0.000 |

R-squared = 0.32

This test determines whether FE or RE is appropriate. stata panel data

Stata Workflow:

* 1. Run Fixed Effects
quietly xtreg y x, fe
* 2. Store the estimates
estimates store fixed
* 3. Run Random Effects
quietly xtreg y x, re
* 4. Store the estimates
estimates store random
* 5. Run the Hausman test
hausman fixed random

Question: Does joining a labor union increase wages, controlling for individual ability?

Data: N=5,000 workers, T=6 years (2015-2020). Variables: wage, union, experience, educ (time-invariant), id, year.

Step 1 – Setup

use union_panel.dta
xtset id year
xtsum wage union experience

Step 2 – Visualize

xtline wage, overlay

Step 3 – Model

* Pooled OLS (with clustering)
regress wage union experience i.year, vce(cluster id)

Step 4 – Interpretation
FE coefficient on union = 0.145 (p<0.01) → Union membership raises wage by 14.5% (semi-elasticity), holding experience and year constant.

Step 5 – Diagnostics

xtserial wage union experience

No serial correlation (p>0.05).

Conclusion: Using Stata panel data methods, we isolate the causal effect of unions.


xtreg ln_wage hours age tenure, fe
estimates store fe
xtreg ln_wage hours age tenure, re
estimates store re
hausman fe re

Rule: If p < 0.05, FE is consistent; RE is inconsistent.

xtreg wage hours tenure age i.year, re