Does foreign direct investment raise growth across 40 countries over 20 years? Do firm characteristics affect profitability over a decade? Questions like these combine many units and many time periods, and plain OLS ignores the fact that the same country or firm appears again and again. Panel data analysis handles that structure and controls for unobserved characteristics that do not change over time. This guide walks through panel data analysis in Stata in eight steps, with commands, output interpretation and reporting for an economics thesis.
This article is part of our guide How to Write a Master’s Thesis by the Mastermind PhD team and relates to our Statistical Analysis service. Sources last checked: November 2026.
What is panel data analysis? Panel data analysis is the set of econometric methods for data that follow the same cross-sectional units (countries, firms, households) over several time periods. Its core models, pooled OLS, fixed effects and random effects, differ in how they treat unobserved unit-specific characteristics, and diagnostic tests decide which model fits the data.

What does panel data look like?
Stata expects long format: one row per unit per year.
| country | year | gdp_growth | fdi | inflation |
|---|---|---|---|---|
| 1 | 2015 | 3.1 | 2.4 | 5.0 |
| 1 | 2016 | 2.7 | 2.9 | 4.2 |
| 2 | 2015 | 4.5 | 1.1 | 8.3 |
| 2 | 2016 | 4.0 | 1.6 | 7.9 |
(Values are illustrative.) A panel is balanced when every unit has every year, and unbalanced when some years are missing; Stata handles both. Data from sources such as the World Bank’s World Development Indicators often arrive in wide format and need reshaping.
How do you run panel data analysis in Stata in 8 steps?
Step 1: Reshape to long format and encode identifiers
encode country_name, gen(country)
reshape long gdp_growth fdi inflation, i(country) j(year)
Here the wide file has columns such as gdp_growth2015 and gdp_growth2016; reshape turns the year suffix into the variable year, and encode creates the numeric identifier that xtset needs.
Step 2: Declare the panel
xtset country year
Stata reports whether the panel is strongly balanced and the time span.
Step 3: Describe the data
xtdescribe
xtsum gdp_growth fdi inflation
xtsum splits the variance into between (across units) and within (over time) components. A variable with almost no within variation cannot be estimated well with fixed effects.
Step 4: Estimate pooled OLS as a baseline
regress gdp_growth fdi inflation, vce(cluster country)
Pooled OLS treats every observation as independent apart from clustering, and ignores unit-specific effects.
Step 5: Estimate fixed effects
xtreg gdp_growth fdi inflation, fe
estimates store fe
Fixed effects use only within-unit variation, so they control for all time-invariant characteristics (geography, legal origin). The output reports R-squared within, between and overall, rho (the share of variance due to unit effects) and an F test that all unit effects equal zero; a significant F favors fixed effects over pooled OLS.
Step 6: Estimate random effects
xtreg gdp_growth fdi inflation, re
estimates store re
xttest0
Random effects assume the unit effects are uncorrelated with the regressors. xttest0 runs the Breusch-Pagan Lagrange multiplier test; a significant result favors random effects over pooled OLS.
Step 7: Choose between fixed and random effects
hausman fe re
The Hausman (1978) test compares the two sets of coefficients. A significant result (p < .05) means the random effects assumption is rejected, and fixed effects are preferred. The standard test requires conventional (non-robust) standard errors; with clustered errors, use a robust alternative such as the user-written xtoverid command or a Mundlak-type auxiliary regression, and say so in the thesis.
Step 8: Diagnose and use robust standard errors
xtreg gdp_growth fdi inflation i.year, fe vce(cluster country)
testparm i.year
testparm tests whether year dummies are jointly needed (time fixed effects). Serial correlation can be checked with the user-written xtserial command (Wooldridge test, described by Drukker, 2003) and groupwise heteroskedasticity after fixed effects with xttest3. Clustered standard errors by unit handle both in most thesis settings.
📱 Ask a statistician about your data — Send a short description of your instrument and sample size on WhatsApp and get a suitable analysis plan. Every analysis comes with the raw SPSS file and a results report.
Which model should you report?
The three tests in steps 5 to 7 form the decision path of panel data analysis:
| Test result | Decision |
|---|---|
| F test for unit effects not significant and LM test not significant | Pooled OLS is acceptable |
| F test significant | Fixed effects better than pooled OLS |
| LM test significant | Random effects better than pooled OLS |
| Hausman significant | Fixed effects |
| Hausman not significant | Random effects (more efficient) |
Many economics theses present pooled OLS, fixed effects and random effects side by side in one table, then justify the preferred model with the tests.

How do you report the results?
A regression table for panel data analysis should show, for each model: coefficients with clustered standard errors in parentheses, significance stars defined in a note, the number of observations and units, R-squared (within for fixed effects), whether unit and year effects are included, and the test statistics (F, LM, Hausman with p-values). Commands such as esttab (from the user-written estout package) or etable in Stata 17 and later export these tables to Word or LaTeX.
In the text, interpret the size of each coefficient, not only its significance: “a one percentage point increase in FDI inflows is associated with a 0.12 point increase in GDP growth, holding inflation constant” (an illustrative sentence).
How should the methodology chapter describe panel data analysis?
Examiners look for five elements: the data sources and indicator codes for every variable; the panel structure (number of units, years, and whether it is balanced); the model equation with unit effects written explicitly, for example y_it = α_i + β·x_it + ε_it, where i indexes units and t years; the sequence of tests used to choose the model; and the treatment of standard errors. State the Stata version and any user-written commands, with their references.
A typical thesis scenario (illustrative)
This constructed example shows the workflow only. A student studies whether remittances are associated with household consumption growth in 25 countries between 2005 and 2022. Panel data analysis begins with xtsum, which shows that remittances vary mainly between countries and only modestly within them. The F test rejects pooled OLS, the LM test rejects pooled OLS in favor of random effects, and the Hausman test is significant, so fixed effects with year dummies and clustered errors become the main model. Because the within variation is small, the discussion chapter notes that the fixed effects estimates are less precise and presents random effects as a robustness check.
What are the common pitfalls?
These errors are easy to make in panel data analysis for a thesis:
- Running fixed effects on time-invariant variables, which are dropped automatically.
- Ignoring non-stationarity in long macro panels; for long time dimensions, consider panel unit root tests (
xtunitroot). - Treating endogeneity as solved by fixed effects; reverse causality still needs instruments or dynamic panel methods such as GMM.
- Reporting the Hausman test with robust standard errors as if it were valid.
- Not stating how missing years were handled.
📱 Ask on WhatsApp now — 5 years of experience across all disciplines and 14 academic services. Two-stage payment (80/20); revisions are free until supervisor approval, within 30% of the chapter.

Frequently asked questions
How many years and units do I need?
There is no fixed minimum, but panel data analysis with very few units makes clustered standard errors unreliable. Many theses use 20 or more units; with few clusters, discuss the limitation.
What is the difference between fixed and random effects in simple terms?
Fixed effects compare each unit with itself over time. Random effects also use differences between units, assuming those unit characteristics are unrelated to the explanatory variables.
Should I include year dummies?
Include them when common shocks such as global crises affect all units in the same year. Test them jointly with `testparm i.year`.
Can I use panel data analysis in SPSS?
SPSS can estimate some models through mixed models, but Stata, R (plm package) and EViews are standard in economics for panel econometrics and diagnostics.
What if my variables are non-stationary?
For long panels, test for unit roots and consider differencing or cointegration methods. Short panels with many units are less affected.
Sources
- StataCorp. Stata longitudinal-data/panel-data reference manual. https://www.stata.com/manuals/xt.pdf (accessed November 2026)
- Wooldridge, J. M. (2010). Econometric analysis of cross section and panel data (2nd ed.). MIT Press.
- Baltagi, B. H. (2021). Econometric analysis of panel data (6th ed.). Springer.
- Hausman, J. A. (1978). Specification tests in econometrics. Econometrica, 46(6), 1251-1271. https://doi.org/10.2307/1913827
- Drukker, D. M. (2003). Testing for serial correlation in linear panel-data models. The Stata Journal, 3(2), 168-177. https://doi.org/10.1177/1536867X0300300206
Sources last checked: November 2026. This article is general educational guidance and does not replace your university regulations or your supervisor’s instructions. How we prepare our content.

