11.5 Panel

Declare panel data

You must xtset your data before you can use other xt commands.

xtset panelvar timevar declares the data to be a panel in which the order of observations is relevant. When you specify timevar, you can then use time series operators (e.g., L, D).

Menu

Statistics > Longitudinal/panel data > Setup and utilities > Declare dataset to be panel data

  • panelvar panel variable that identifies the unit
  • timevar optional time variable that identifies the time within panels

Use describe to show an overview of data structure.

Sometimes numbers will get recorded as string variables, making it impossible to do almost any command.

destring [varlist], {gen(newvarlist) | replace} [options]
  • gen(newvarlist) generate new variables for each variable in varlist.
  • replace replace string variables with numeric variables
  • ignore("chars") specifies nonnumeric characters be removed.
// from logd_gdp to rad, convert to numeric, replace "NA" with missing
destring logd_gdp-rad, replace ignore(`"NA"')

xtreg is Stata’s feature for fitting linear models for panel data.

xtreg, fe estimates the parameters of fixed-effects models:

xtreg depvar [indepvars] [if] [in] [weight] , fe [FE_options]

Menu: Statistics > Longitudinal/panel data > Linear models > Linear regression (FE, RE, PA, BE, CRE)

Options

  • vce(robust) use clustered variance that allows for intragroup correlation within groups.

    By default, SE uses OLS estimates.