Study guideEconometricsQatar

Running Your First Panel Regression in Stata, Step by Step: A Study Guide for Finance PhD Scholars in Qatar

What you will learn

  • Declare a panel with xtset and check balance with xtdescribe and xtsum
  • Estimate pooled OLS, fixed effects and random effects with firm-clustered standard errors
  • Choose between fixed and random effects with a test that suits clustered errors
  • Adapt the steps to a small market such as Qatar, with few firms and short panels

What you will unlearn

  • Pooled OLS is fine if the R-squared looks good.Pooled OLS ignores firm differences; report it only as a baseline beside fixed and random effects.
  • The classic Hausman test always settles fixed versus random effects.The classic test is not valid with clustered errors; use the Mundlak (auxiliary regression) test instead.
  • Default standard errors are good enough for a finance panel.The same firm’s years are correlated, so cluster standard errors by firm.

Skills you will practise

  • Declaring panel data in Stata
  • Running fixed and random effects
  • Clustering standard errors
  • Testing fixed against random effects
  • Reporting a comparison table

Overview

This panel data analysis tutorial shows how to run panel regression in Stata, step by step: put your data in long format (one row per firm per year), declare the panel with xtset, estimate pooled OLS, fixed effects and random effects with firm-clustered standard errors, choose between fixed and random effects with a cluster-robust test, then report all three side by side.

At a glance

  • Panel data follows the same firms or banks over several years, so each firm’s fixed traits must be handled.
  • Fixed effects is the usual default in corporate finance. Random effects needs a stronger assumption.
  • With clustered standard errors, the classic Hausman test is not valid. Use the Mundlak test instead.
  • Small markets such as Qatar give short, unbalanced panels, so report the number of firms and years.
  • Save every command in a do-file.

If your finance thesis follows the same firms or banks over several years, a simple regression is not enough. Think of companies listed on the Qatar Stock Exchange, or banks across the GCC, observed from 2010 to 2023. Each firm has characteristics, such as management culture or founding history, that stay with it over time, and your model has to account for them [1][2]. The example below regresses return on assets (roa) on leverage (lev), firm size (size) and sales growth (growth). It is a Stata regression step by step guide for doctoral scholars in Qatar who are running their first panel model and want to defend it with confidence.

How to Run Panel Regression in Eight Steps

Step 1: Prepare your data in long format

Panel data needs one row for each firm in each year, with columns for the firm ID, the year and each variable. If your Bloomberg or Refinitiv download lists years across columns, reshape it first:

reshape long roa lev size growth, i(firm_id) j(year)
duplicates report firm_id year

Check for duplicate rows, missing years and obvious entry errors. A small mistake here quietly affects every result that follows.

Step 2: Declare the panel

Tell Stata which variable identifies the firm and which identifies time:

xtset firm_id year

Without this, Stata treats the data as unrelated observations and cannot apply panel estimators. Once the panel is declared, later xt commands use the structure automatically.

Step 3: Check the panel structure and clean your variables

xtdescribe
xtsum roa lev size growth
  • xtdescribe shows whether every firm appears in every year. Unbalanced panels are common in small markets because firms list, delist or stop reporting. They are acceptable if you report the number of firms and observations.
  • xtsum splits each variable’s variation into between firms and within firms. A variable that never changes over time, such as sector, cannot be estimated in a fixed effects model.
  • Winsorise extreme financial ratios (often at the 1st and 99th percentiles) and state this in your methodology.

Step 4: Run a pooled OLS baseline

regress roa lev size growth, vce(cluster firm_id)
estimates store pooled

Cluster standard errors by firm, because observations from the same firm are correlated over time [3][4]. Pooled OLS assumes all firms are alike, which is rarely true, so treat it as a baseline only.

Step 5: Run the fixed effects model

xtreg roa lev size growth i.year, fe vce(cluster firm_id)
estimates store fe

Fixed effects (the within estimator) uses only changes inside each firm over time, so anything about a firm that does not change, whether you measured it or not, is removed [1]. Adding i.year controls for shocks that hit every firm in the same year, such as an oil-price fall. Check the within R², which tells you how much of the variation inside firms the model explains, and check the sign and size of each coefficient against your hypotheses.

Step 6: Run the random effects model

xtreg roa lev size growth i.year, re vce(cluster firm_id)
estimates store re

Random effects assumes that each firm’s unobserved characteristics are unrelated to the regressors. That is a stronger assumption than fixed effects needs, but if it holds, the estimates are more precise and time-invariant variables can stay in the model [2].

Step 7: Choose between fixed and random effects

The classic Hausman test compares the two models. A significant result favours fixed effects [5]:

quietly xtreg roa lev size growth i.year, fe
estimates store fe_h
quietly xtreg roa lev size growth i.year, re
estimates store re_h
hausman fe_h re_h

The standard Hausman test is only valid without clustered errors. If you cluster, as you should here, use the Mundlak (correlated random effects) test. Add the firm means of the time-varying regressors to the random effects model and test whether they are jointly zero [6]:

foreach v in lev size growth {
bysort firm_id: egen m_`v' = mean(`v')
}
xtreg roa lev size growth m_lev m_size m_growth i.year, re vce(cluster firm_id)
test m_lev m_size m_growth

A significant result rejects random effects in favour of fixed effects. State which test you used and why. Examiners care about your reasoning as much as the result.

Step 8: Interpret and report your results

  • Put pooled OLS, fixed effects and random effects side by side in one table, with the number of firms, observations and the clustering level beneath it.
  • Explain each coefficient in plain terms, for example what a one-unit rise in leverage means for return on assets, and say whether the effect is economically meaningful and not only statistically significant.
  • Save every command in a do-file so the analysis can be rerun after supervisor feedback.

For reporting conventions, see reporting econometric results in finance.

A note for small markets like Qatar

Qatar panels are often short (few years) and narrow (few firms), and firms in a small market tend to move together. Keep the model simple, cluster by firm, and test for cross-sectional dependence before trusting the standard errors. The Stata and R walkthrough covers those checks.

FAQ

  1. Should I use fixed or random effects for a finance thesis?
Fixed effects is the usual default for firm-level data, because unobserved firm traits are likely to be related to leverage or size. Use a cluster-robust Mundlak test to justify the choice.
  1. Can I run the Hausman test with clustered standard errors?
Not the standard version. Use the Mundlak test shown in Step 7, or a cluster-robust overidentification test.
  1. Why did my sector dummy drop out of the fixed effects model?
Fixed effects removes anything that does not change within a firm over time, so time-invariant variables cannot be estimated.
  1. Is an unbalanced panel a problem?
Not by itself. Report the number of firms and observations, and check whether firms leave the sample for reasons linked to your outcome.

Next step

Once you are comfortable with these eight steps, take them further with Panel Regression and Time-Series Analysis in Stata and R: A Downloadable Walkthrough for Qatar Scholars.

For finance PhD scholars in Qatar

If you want a second pair of eyes on your model choice, Stata code or results chapter, PhD Assistance’s econometrics team can review your panel analysis and help you defend it. Our finance data analysis and econometrics support guides Qatar doctoral scholars through model selection, Stata and R coding and results interpretation.

Your next step

Want to apply this to your own study?

  1. 1Tell us your topic, data and deadline
  2. 2A subject mentor reviews your work with you
  3. 3You get a plan and a quote
Econometrics support

References

  1. Wooldridge, J. M. (2010). Econometric analysis of cross section and panel data (2nd ed.). MIT Press.
  2. Baltagi, B. H. (2021). Econometric analysis of panel data (6th ed.). Springer. https://doi.org/10.1007/978-3-030-53953-5
  3. Petersen, M. A. (2009). Estimating standard errors in finance panel data sets: Comparing approaches. Review of Financial Studies, 22(1), 435–480. https://doi.org/10.1093/rfs/hhn053
  4. Cameron, A. C., & Miller, D. L. (2015). A practitioner’s guide to cluster-robust inference. Journal of Human Resources, 50(2), 317–372. https://doi.org/10.3368/jhr.50.2.317
  5. Hausman, J. A. (1978). Specification tests in econometrics. Econometrica, 46(6), 1251–1271. https://doi.org/10.2307/1913827
  6. Mundlak, Y. (1978). On the pooling of time series and cross section data. Econometrica, 46(1), 69–85. https://doi.org/10.2307/1913646

How to cite this article

Choose your referencing style, then copy. Check your university's or journal's guide for local variations.

PhD Research Lab Academy. (2026, November 15). Running Your First Panel Regression in Stata, Step by Step: A Study Guide for Finance PhD Scholars in Qatar. PhD Research Lab. https://www.phdassistance.com/study-guide/how-to-run-panel-regression-stata/

PhD Research Lab Academy. “Running Your First Panel Regression in Stata, Step by Step: A Study Guide for Finance PhD Scholars in Qatar.” PhD Research Lab, 15 Nov. 2026, www.phdassistance.com/study-guide/how-to-run-panel-regression-stata. Accessed [access date].

PhD Research Lab Academy (2026) Running Your First Panel Regression in Stata, Step by Step: A Study Guide for Finance PhD Scholars in Qatar. PhD Research Lab. Available at: https://www.phdassistance.com/study-guide/how-to-run-panel-regression-stata/ (Accessed: [access date]).

PhD Research Lab Academy. “Running Your First Panel Regression in Stata, Step by Step: A Study Guide for Finance PhD Scholars in Qatar.” PhD Research Lab. November 15, 2026. https://www.phdassistance.com/study-guide/how-to-run-panel-regression-stata.

PhD Research Lab Academy, ‘Running Your First Panel Regression in Stata, Step by Step: A Study Guide for Finance PhD Scholars in Qatar’ (PhD Research Lab, 15 November 2026) <https://www.phdassistance.com/study-guide/how-to-run-panel-regression-stata> accessed [access date].

PhD Research Lab Academy. Running Your First Panel Regression in Stata, Step by Step: A Study Guide for Finance PhD Scholars in Qatar [Internet]. PhD Research Lab; 2026 Nov 15 [cited [access date]]. Available from: https://www.phdassistance.com/study-guide/how-to-run-panel-regression-stata/

PhD Research Lab Academy, “Running Your First Panel Regression in Stata, Step by Step: A Study Guide for Finance PhD Scholars in Qatar,” PhD Research Lab, Nov. 15, 2026. [Online]. Available: https://www.phdassistance.com/study-guide/how-to-run-panel-regression-stata. [Accessed: [access date]].

@online{sgpnl_2026,
  author = {{PhD Research Lab Academy}},
  title = {{Running Your First Panel Regression in Stata, Step by Step: A Study Guide for Finance PhD Scholars in Qatar}},
  organization = {PhD Research Lab},
  date = {2026-11-15},
  url = {https://www.phdassistance.com/study-guide/how-to-run-panel-regression-stata},
  urldate = {[access date]}
}

This article is for learning. Use it to understand the method and cite the original sources above in your own work; do not copy or submit it as your own.

Panel regression in StataNeed help applying it to your study?
Econometrics support