**[XT] xtgls** -- Fit panel-data models by using GLS

__Syntax__

**xtgls** *depvar* [*indepvars*] [*if*] [*in*] [*weight*] [**,** *options*]

*options* Description
-------------------------------------------------------------------------
Model
__nocons__**tant** suppress constant term
__p__**anels(**__i__**id)** use i.i.d. error structure
__p__**anels(**__h__**eteroskedastic)** use heteroskedastic but uncorrelated error
structure
__p__**anels(**__c__**orrelated)** use heteroskedastic and correlated error
structure
__c__**orr(**__i__**ndependent)** use independent autocorrelation structure
__c__**orr(**__a__**r1)** use AR1 autocorrelation structure
__c__**orr(**__p__**sar1)** use panel-specific AR1 autocorrelation
structure
__rho__**type(***calc***)** specify method to compute autocorrelation
parameter; see *Options* for details; seldom
used
**igls** use iterated GLS estimator instead of two-step
GLS estimator
**force** estimate even if observations unequally spaced
in time

SE
**nmk** normalize standard error by N-k instead of N

Reporting
__l__**evel(***#***)** set confidence level; default is **level(95)**
*display_options* control columns and column formats, row
spacing, line width, display of omitted
variables and base and empty cells, and
factor-variable labeling

Optimization
*optimize_options* control the optimization process; seldom used

__coefl__**egend** display legend instead of statistics
-------------------------------------------------------------------------
A panel variable must be specified. For correlation structures other than
**independent**, a time variable must be specified. A time variable must
also be specified if **panels(correlated)** is specified. Use **xtset**.
*indepvars* may contain factor variables; see fvvarlist.
*depvar* and *indepvars* may contain time-series operators; see tsvarlist.
**by** and **statsby** are allowed; see prefix.
**aweight**s are allowed; see weight.
**coeflegend** does not appear in the dialog box.
See **[XT] xtgls postestimation** for features available after estimation.

__Menu__

**Statistics > Longitudinal/panel data > Contemporaneous correlation >** **GLS**
**regression with correlated disturbances**

__Description__

**xtgls** fits panel-data linear models by using feasible generalized least
squares. This command allows estimation in the presence of AR(1)
autocorrelation within panels and cross-sectional correlation and
heteroskedasticity across panels.

__Options__

+-------+
----+ Model +------------------------------------------------------------

**noconstant**; see **[R] estimation options**.

**panels(***pdist***)** specifies the error structure across panels.

**panels(iid)** specifies a homoskedastic error structure with no
cross-sectional correlation. This is the default.

**panels(heteroskedastic)** specifies a heteroskedastic error structure
with no cross-sectional correlation.

**panels(correlated)** specifies a heteroskedastic error structure with
cross-sectional correlation. If **p(c)** is specified, you must also
specify a time variable (use **xtset**). The results will be based on a
generalized inverse of a singular matrix unless T>=m (the number of
periods is greater than or equal to the number of panels).

**corr(***corr***)** specifies the assumed autocorrelation within panels.

**corr(independent)** specifies that there is no autocorrelation. This
is the default.

**corr(ar1)** specifies that, within panels, there is AR(1)
autocorrelation and that the coefficient of the AR(1) process is
common to all the panels. If **c(ar1)** is specified, you must also
specify a time variable (use **xtset**).

**corr(psar1)** specifies that, within panels, there is AR(1)
autocorrelation and that the coefficient of the AR(1) process is
specific to each panel. **psar1** stands for panel-specific AR(1). If
**c(psar1)** is specified, a time variable must also be specified; use
**xtset**.

**rhotype(***calc***)** specifies the method to be used to calculate the
autocorrelation parameter:

**regress** regression using lags; the default
**dw** Durbin-Watson calculation
**freg** regression using leads
**nagar** Nagar calculation
**theil** Theil calculation
**tscorr** time-series autocorrelation calculation

All the calculations are asymptotically equivalent and consistent;
this is a rarely used option.

**igls** requests an iterated GLS estimator instead of the two-step GLS
estimator for a nonautocorrelated model or instead of the three-step
GLS estimator for an autocorrelated model. The iterated GLS
estimator converges to the MLE for the **corr(independent)** models but
does not for the other **corr()** models.

**force** specifies that estimation be forced even though the time variable
is not equally spaced. This is relevant only for correlation
structures that require knowledge of the time variable. These
correlation structures require that observations be equally spaced so
that calculations based on lags correspond to a constant time change.
If you specify a time variable indicating that observations are not
equally spaced, the (time dependent) model will not be fit. If you
also specify **force**, the model will be fit, and it will be assumed
that the lags based on the data ordered by the time variable are
appropriate.

+----+
----+ SE +---------------------------------------------------------------

**nmk** specifies that standard errors normalized by N-k, where k is the
number of parameters estimated, rather than N, the number of
observations. Different authors have used one or the other
normalization. Greene (2018, 313) remarks that whether a
degree-of-freedom correction improves the small-sample properties is
an open question.

+-----------+
----+ Reporting +--------------------------------------------------------

**level(***#***)**; see **[R] estimation options**.

*display_options*: **noci**, __nopv__**alues**, __noomit__**ted**, **vsquish**, __noempty__**cells**,
__base__**levels**, __allbase__**levels**, __nofvlab__**el**, **fvwrap(***#***)**, **fvwrapon(***style***)**,
**cformat(***%fmt***)**, **pformat(%***fmt***)**, **sformat(%***fmt***)**, and **nolstretch**; see **[R]**
**estimation options**.

+--------------+
----+ Optimization +-----------------------------------------------------

*optimize_options* control the iterative optimization process. These
options are seldom used.

__iter__**ate(***#***)** specifies the maximum number of iterations. When the
number of iterations equals #, the optimization stops and presents
the current results, even if convergence has not been reached. The
default is **iterate(100)**.

__tol__**erance(***#***)** specifies the tolerance for the coefficient vector.
When the relative change in the coefficient vector from one iteration
to the next is less than or equal to #, the optimization process is
stopped. **tolerance(1e-7)** is the default.

**nolog** suppress the display of the iteration log.

The following option is available with **xtgls** but is not shown in the
dialog box:

**coeflegend**; see **[R] estimation options**.

__Examples__

Setup
**. webuse invest2**
**. xtset company time**

Fit panel-data model with heteroskedasticity across panels
**. xtgls invest market stock, panels(hetero)**

Correlation and heteroskedasticity across panels
**. xtgls invest market stock, panels(correlated)**

Heteroskedasticity across panels and autocorrelation within panels
**. xtgls invest market stock, panels(hetero) corr(ar1)**

__Stored results__

**xtgls** stores the following in **e()**:

Scalars
**e(N)** number of observations
**e(N_g)** number of groups
**e(N_t)** number of periods
**e(N_miss)** number of missing observations
**e(n_cf)** number of estimated coefficients
**e(n_cv)** number of estimated covariances
**e(n_cr)** number of estimated correlations
**e(df_pear)** degrees of freedom for Pearson chi-squared
**e(chi2)** chi-squared
**e(df)** degrees of freedom
**e(g_min)** smallest group size
**e(g_avg)** average group size
**e(g_max)** largest group size
**e(rank)** rank of **e(V)**
**e(rc)** return code

Macros
**e(cmd)** **xtgls**
**e(cmdline)** command as typed
**e(depvar)** name of dependent variable
**e(ivar)** variable denoting groups
**e(tvar)** variable denoting time within groups
**e(coefftype)** estimation scheme
**e(corr)** correlation structure
**e(vt)** panel option
**e(rhotype)** type of estimated correlation
**e(wtype)** weight type
**e(wexp)** weight expression
**e(title)** title in estimation output
**e(chi2type)** **Wald**; type of model chi-squared test
**e(rho)** rho
**e(properties)** **b V**
**e(predict)** program used to implement **predict**
**e(asbalanced)** factor variables **fvset** as **asbalanced**
**e(asobserved)** factor variables **fvset** as **asobserved**

Matrices
**e(b)** coefficient vector
**e(Sigma)** Sigma hat matrix
**e(V)** variance-covariance matrix of the estimators

Functions
**e(sample)** marks estimation sample

__Reference__

Greene, W. H. 2018. *Econometric Analysis*. 8th ed. New York: Pearson.