*! version 1.0 19nov2013

Title

gsreg -- Global Search Regression

Syntax

gsreg depvar _ocand [if] [in] [weight]
[,
ncomb(#1,#2)
samesample
vselect
dlags(numlist)
ilags(numlist)
lags(numlist)
fixvar(varlist_fix)
schange(varname_sc)
interactions
squares
cubic
fixinteractions
outsample(#)
cmdest(commandname)
cmdoptions(commandoptions)
cmdstat(commandstats)
cmdiveq(varlist_end = varlist_inst)
aicbic
hettest
hettest_o(hettestmoptions)
archlm
archlm_o(archlmoptions)
bgodfrey
bgodfrey_o(bgodfreyoptions)
durbinalt
durbinalt_o(durbinaltoptions)
dwatson
sktest
sktest_o(sktestoptions)
swilk
swilk_o(swilkoptions)
sfrancia
testpass(#)
resultsdta(newbasename)
replace
double
nocount
compact
nindex(lcimplist)
mindex(lcimplist)
best(#)
backup(#)
part(#1,#2)]

fweights, aweights, and pweights are allowed depending on the estimation command specified in cmdest(commandname); see
weight.

Sections

Main sections are presented under the following headings:

Description

Options

Examples

Saved results

Description

gsreg is an automatic model selection command for time series,
cross-section and panel data regressions. By default (otherwise, users
have many options to modify this simplest specification), gsreg performs
alternative OLS regressions looking for the best depvar Data Generating
Process, iterating over all possible combinations among explanatory variables
specified in _ocand. Regression results are stored in a .dta file
named as gsreg.dta, and saved in the working directory. This database
assigns one row for each regression and includes the following columns:

1) regression id (variable order)

2) covariate regression coefficients (named v_1_b, v_2_b… , etc.,
and labeled with the full covariate name plus the word “coeff.”)

3) coefficient t-statistics (named v_1_t, v_2_t…, etc., and labeled
with the full covariate name plus the word “tstat.”)

4) number of observations (variable obs)

5) number of covariates -including the intercept- (variable nvar)

6) adjusted R2 (variable r_sqr_a)

7) in-sample root mean square error (variable rmse_in)

8) normalized linear combination of user selected (and weighted) model
selection criteria (as nindex or mindex if this option is specified).
By default nindex is the normalized adjusted R2.

.gsreg depvar ocand1 ocand2

runs the 3 following regressions

regress depvar ocand1

regress depvar ocand2

regress depvar ocand1 ocand2

and generates a gsreg.dta database like:

order	v_1_b	v_1_t	v_2_b	v_2_t	v_3_b	v_3_t	obs	nvar	r_sqr_a	rmse_in	nindex
1	#	# #	#	#	2	#	#	#
2 #	#	#	#	#	2	#	#	#
3	#	#	#	#	#	#	#	3	#	#	#

Below is a description of each variable of the dataset:

.use gsreg.dta

.describe

variable	variable label
---------	--------------
order order number of estimation
v_1_b ocand1 coeff.
v_1_t ocand1 tstat.
v_2_b ocand2 coeff.
v_2_t ocand2 tstat.
v_3_b intercept coeff.
v_3_t intercept tstat.
obs number of observations
nvar number of covariates
r_sqr_a adjusted R-squared
rmse_in in-sample RMSE
nindex normalized linear combination of model selection criteria

Back to Top

Options

General options

ncomb(#1,#2) specifies the minimum and maximum number of variable
(instead of user-specified fixed) covariates to be included in the procedure. gsreg
will perform all possible combinations (regressions) between candidate variables taken
from #1 to #2. #1 must be less or equal to #2 and, additionally,
the number of candidates must be greater or equal to #2. If this option is not
specified, gsreg will run all possible combinations without repetition of size
1 to n (the total number of candidates). See Examples of using ncomb

samesample makes all regressions to be performed over the same
sample of observations, defined as the largest common sample. By default, gsreg
performs each regression with the maximum number of common observations available
for the covariate subset used in each particular case.
See Examples of using samesample

nocount hides from the screen the number of regression which is being
estimated. If this option is not specified, gsreg will show for each
alternative model, the regression number (used for identification purposes) and
the total number of regressions to be estimated.

backup(#) creates # backup files during the execution of gsreg. Each backup
will contain approximately 1/# regressions. Each file will be saved in the ongoing working
directory and will be named with the name of the result database (gsreg by default),
plus the number of partition and the total number of backups specified in #
(eg. gsreg_ part_1_of_#.dta). All partitions will be deleted at the end of the execution
of gsreg and result database with all results will be saved. If number of regressions
is lower than #, the number of partitions will be reset to the number of regressions.
See Examples of using backup and part

part(#1,#2) runs a specific partition of all regressions. The partition will contain
approximately 1/#2 regressions. gsreg will save the partition (instead of the result
database) in the ongoing working directory. If total number of regressions is lower than #2, the
number of partitions (#2) will be reset to the number of regressions.
See Examples of using backup and part

vselect runs the command vselect (using the vselect “best”
option) developed by Charles Lindsey and Simon Sheather (2010), which has to
be previously installed) to obtain the best n regressions (one for each maximum
number of covariates included in regressions: e.g. the best one covariate model,
the best two-covariates model, and so on) in terms of in-sample RMSE. Using vselect,
the only additional gsreg option that can be specified is the fixvar option.
See Examples of using vselect

Lag structure options

dlags(numlist) allows to include dependent variable lags (depvar) among
candidate covariates. tsset must be specified when using this option.
See Examples of using dlag, ilags or lags

dlags(#) adds among candidates the # dependent variable lag.

dlags(#1/#2) adds among candidates all dependent variable lags from #1 to
#2 considering one-unit intervals.

dlags(#1 #2 #3) adds among candidates the #1, the #2, and the #3
dependent variable lags.

dlags(#1 (#d) #2) adds among candidates all dependent variable lags from #1
to #2 considering #d unit intervals.

dlags(#1 #2 #3 … #4 (#d) #5) adds among candidates dependent variable lags #1
, #2, and #3, and additionally all dependent variable lags from #4 to
#5 considering #d unit intervals.

ilags(numlist) allows including independent variable lags among original candidates.
The syntax is flexible and identical to that used in dlags.
See Examples of using dlag, ilags or lags

lags(numlist) allows to jointly include dependent and independent variable lags
among original candidates. It replaces dlags and ilags when the argument is
identical. tsset must be specified when using this option. lags must not be specified
together with dlags or ilags.
See Examples of using dlag, ilags or lags

Fixed variable options

fixvar(varlist_fix) allows users to specify a subset of covariates which must be
included in all regressions. Variables defined in _fix must not be included
among the standard candidates (varlist_ocand).
See Examples of using fixvar

Options for transformations and interactions

schange(varname_sc) tests structural change of slops (using dummy _sc as
interaction with all candidates) or dependent variable levels (alternatively allowing
_sc to interact with the intercept). Interactions of _sc with any candidate
will only be included if this candidate is in the equation. _sc must not be included
among original candidates (varlist_ocand) because it will only be used for
structural change.
See Examples of using transformations and interactions

interactions includes additional covariate candidates to evaluate all possible
interactions without repetition among original candidates (varlist_ocand)
and lags, if specified in dlags, ilags or
lags. Interactions between any two candidates will only be allowed
if both of them are in the equation. When used together with schange, the structural
change of interactions will only be used if these interactions are included in the estimated
specification.
See Examples of using transformations and interactions

squares adds the squares of each variable in varlist_ocand
(and lags, if specified in dlags, ilags
or lags) as new candidates. Each square will only be accepted as
a regression covariate if its level (original variable) is present in the equation.
Similarly, when used together with schange, the structural change of the squares
will only be allowed if these squares are in the equation.
See Examples of using transformations and interactions

cubic is similar to squares. It includes cubes of each variable in
varlist_ocand (and lags, if specified in dlags,
ilags or lags) as new candidates.
These cubes will only be accepted as covariates if level and squares of the same
variable are also included in the equation. As for squares, when used together
with schange, the structural change of the cubes will only be allowed if these
cubes are also in the equation.
See Examples of using transformations and interactions

fixinteractions is similar to interactions, but it includes as additional
candidates all possible interactions without repetition among varlist_ocand
(and lags, if specified in dlags, ilags or
lags) and each fixed variable in varlist_fix.
See Examples of using transformations and interactions

Options for time series and panel data forecasts

outsample(#) is used in time series and panels models. It splits the sample into two.
The first sub-sample is used for regression purposes and the second one is applied to evaluate
forecast accuracy. outsample(#) leaves the last # periods to make forecasts (so that
regressions are performed over the first T-# periods – where T is the total number of
available time series observations). When this option is specified, gsreg calculates and
store the rmse_in (in sample root mean square error) between period 1 and N-#, and
rmse_out (out sample root mean square error) between period N-# and N. tsset must be
specified when using this option.
See Examples of using outsample

Regression command options

cmdest(commandname) allows choosing the regression command to be used. If the option is
not specified, commandname default is regress. This option allows using
regress, xtreg, probit,
logit, areg, qreg and plreg,
but it additionally accept any regression command that respects the syntax of
regress
and saves results (matrices e(b) and e(V)) in the same way. ivregress
is also acepted using option cmdiveq(varlist_end = varlist_inst).
See Examples of using cmdest, cmdoptions, cmdstat and cmdiveq

cmdoptions(commandoptions) allows adding supported (by commandname) additional
options for each regression.
See Examples of using cmdest, cmdoptions, cmdstat and cmdiveq

cmdstat(commandstats) enables gsreg (which automatically saves the number of
observations -obs–, the number of covariates -nvar–,
the adjusted R2 -r_sqr_a– and the root mean square error -rmse_in–)
to save additional regression statistics saved as scalars e() by the regression
command (commandname).
See Examples of using cmdest, cmdoptions, cmdstat and cmdiveq

cmdiveq(varlist_end = varlist_inst) is a special option to include a varlist
of endogenous variables (varlist_end) and of instruments (varlist_inst) when
the estimator command is ivregress. When using this option,
cmdest(ivregress 2sls), cmdest(ivregress liml) or cmdest(ivregress gmm)
must be specified. The endogenous variables must be included in varlist_fix
(see option fixvar) or in varlist_ocand).
See Examples of using cmdest, cmdoptions, cmdstat and cmdiveq

Post-estimation options

Information criteria

aicbic calculates estat ic after each regression to
obtain Akaike (aic) and Bayesian information criteria (bic).
See Examples of using Post-estimation options

Heteroscedasticity tests

hettest calculates default estat hettest
after each regression and saves p-values.
See Examples of using Post-estimation options

hettest_o(hettestmoptions) allows adding options to hettest.
See Examples of using Post-estimation options

archlm runs default estat archlm
after each regression and saves p-values. tsset must be specified when using this option.
See Examples of using Post-estimation options

archlm_o(archlmoptions) allows adding options to archlm.
See Examples of using Post-estimation options

Serial autocorrelation tests

bgodfrey computes default estat bgodfrey
after each regression and saves p-values. tsset must be specified when using this option.
See Examples of using Post-estimation options

bgodfrey_o(bgodfreyoptions) allows adding options to bgodfrey.
See Examples of using Post-estimation options

durbinalt calculates estat durbinalt
after each regression and saves the p-values. tsset must be specified when using this option.
See Examples of using Post-estimation options

durbinalt_o(durbinaltoptions) allows adding options to durbinalt.
See Examples of using Post-estimation options

dwatson runs estat dwatson after each
regression and saves the Durbin-Watson statistic. tsset must be specified when using this option.
See Examples of using Post-estimation options

Normality tests of residuals

sktest computes sktest after each regression and saves the p-value
of the joint probability of skewness and kurtosis for normality. tsset must be specified when using this option.
See Examples of using Post-estimation options

sktest_o(sktestoptions) allows adding options to sktest.
See Examples of using Post-estimation options

swilk calculates swilk after each regression and saves the p-value
of the Shapiro-Wilk normality test. tsset must be specified when using this option.
See Examples of using Post-estimation options

swilk_o(swilkoptions) allows adding options to swilk.
See Examples of using Post-estimation options

sfrancia runs sfrancia after each regression and saves the p-value
of the Shapiro-Francia normality test. tsset must be specified when using this option.
See Examples of using Post-estimation options

testpass(#) allows a reduction of the outcome database size by saving only those
regression results that fulfilled all user-specified residual tests (at a # significance level).
See Examples of using Post-estimation options

Output options

resultsdta(newbasename) allows results database name to be user defined
in newbasename. By default, the name will be gsreg.dta.

replace replaces the results database if it is already created (with
the same name) in the ongoing working directory.

double forces results to be created and saved in double
format, that is, with double precision.

compact reduces the results database size by deleting all coefficients
and t-statistics. In their place, gsreg creates a string
variable called regressors that describes which candidate variables are included
in each regression. This variable takes value “1” in position # if the candidate
variable with position # is included in the equation, and it takes value “.” if
it is not. Variable positions are kept in a small database called newbasename_labels.dta
(where newbasename is the results database user defined name).
See Examples of using output options

nindex(lcimplist) allows specifying an index of normalized accuracy
–nindex-. Regressions will be ordered from highest to lowest in the results
database, the best regression according to nindex will be shown on screen and e()
results of this regression will be saved in memory at the end of the gsreg execution.
If not specified, nindex will be based on the adjusted R-squared (r_sqr_a). User choices
about goodness-of-fit or forecast accuracy criteria on nindex can flexibly be specified in
lcimplist. By means of user-selected weights and ranking variables, lcimplist allows
complex arguments to create multinomial ordering criteria. Any results-database variable can
be used in the lcimplist argument as a ranking variable (e.g. r_sqr_a, rmse_in,
rmse_out, aic, bic, etc.), but it must be preceded by a user-defined real number
weight as in the following example: nindex(0.3 r_sqr_a -0.3 aic -0.4 bic). It should be
noticed that each variable included in lcimplist is normalized using the whole sample
average (across of all regressions) of the same variable.
See Examples of using output options

mindex(lcimplist) and best(#) options must be specified
together. mindex generates a normalized ranking index like nindex –mindex-,
and has the same syntax as nindex, but the normalization of its arguments is developed
using averages obtained from the best #+1 regressions. Therefore, mindex is updated with
each additional regression and only the best (in terms of lcimplist) # regressions
results are saved. The joint use of mindex and best options can strongly reduce
database size (and RAM requirements) making feasible larger model selection problems.
However, as mindex must be re-calculated with every regression, gsreg could
run slower than using nindex (particularly for small model selection problems).
See Examples of using output options

Back to Top

Examples

. sysuse auto

. gsreg mpg weight foreign

In this case there are 2 candidate covariates (weight and foreign), gsreg will
perform all possible combinations (regressions) without repetition taken from 2:

regress mpg weight

regress mpg foreign

regress mpg weight foreign

Examples of using ncomb

. gsreg depvar ocand1 ocand2 ocand3, ncomb(1,1)

or equivalently

. gsreg depvar ocand1 ocand2 ocand3, ncomb(1)

In this case there are 3 candidate covariates, gsreg will perform all
possible combinations (regressions) without repetition of size 1 taken from 3:

regress depvar ocand1

regress depvar ocand2

regress depvar ocand3

. gsreg depvar ocand1 ocand2 ocand3, ncomb(1,2)

will perform all possible combinations (regressions) without repetition
of size 1 and 2, taken from 3, that is, it will perform the following 6 regressions:

regress depvar ocand1

regress depvar ocand2

regress depvar ocand3

regress depvar ocand1 ocand2

regress depvar ocand1 ocand3

regress depvar ocand2 ocand3

. gsreg depvar ocand1 ocand2 ocand3, ncomb(1,3)

or equivalently

. gsreg depvar ocand1 ocand2 ocand3

gsreg will perform all possible combinations (regressions) without repetition
of size 1 to 3, taken from 3:

regress depvar ocand1

regress depvar ocand2

regress depvar ocand3

regress depvar ocand1 ocand2

regress depvar ocand1 ocand3

regress depvar ocand2 ocand3

regress depvar ocand1 ocand2 ocand3

Back to General options

Back to Top

Examples of using samesample

suppose depvar, ocand1 and ocand2 have 50 nonmissing
observations but ocand3 has only 48, then

. gsreg depvar ocand1 ocand2 ocand3, ncomb(1)

will perform the following 3 regressions:

regress depvar ocand1, with 50 observations

regress depvar ocand2, with 50 observations

regress depvar ocand3, with 48 observations

while:

. gsreg depvar ocand1 ocand2 ocand3, ncomb(1) samesample

will perform the following 3 regressions:

regress depvar ocand1, with 48 observations

regress depvar ocand2, with 48 observations

regress depvar ocand3, with 48 observations

Back to General options

Back to Top

Examples of using backup and part

. gsreg depvar ocand1 ocand2 ocand3, backup(3)

will perform the same 7 regressions that:

. gsreg depvar ocand1 ocand2 ocand3

But during the execution will save 3 temporary files
in the ongoing working directory:

gsreg_part_1_of_3.dta, containing the outputs of regressions 1 and 2

gsreg_part_2_of_3.dta, containing the outputs of regressions 3 to 5

gsreg_part_3_of_3.dta, containing the outputs of regressions 6 and 7

. gsreg depvar ocand1 ocand2 ocand3 ocand4 ocand5 ocand6 ocand7 ocand8 ocand9, backup(3)

will perform the same 511 regressions that

. gsreg depvar ocand1 ocand2 ocand3 ocand4 ocand5 ocand6 ocand7 ocand8 ocand9

But during the execution will save 3 temporary files
in the ongoing working directory:

gsreg_part_1_of_3.dta, containing the outputs of regressions 1 and 170

gsreg_part_2_of_3.dta, containing the outputs of regressions 171 to 341

gsreg_part_3_of_3.dta, containing the outputs of regressions 342 and 511

. gsreg depvar ocand1 ocand2 ocand3 ocand4 ocand5 ocand6 ocand7 ocand8 ocand9, part(1,3)

will perform only 170 of the 511 regressions and will save
gsreg_part_1_of_3.dta containing the outputs of regressions 1 to 170

. gsreg depvar ocand1 ocand2 ocand3 ocand4 ocand5 ocand6 ocand7 ocand8 ocand9, part(2,3)

will perform only 171 of the 511 regressions and will save
gsreg_part_2_of_3.dta containing the outputs of regressions 171 to 341

Back to General options

Back to Top

Examples of using vselect

. gsreg depvar ocand1 ocand2 ocand3, vselect

will execute

. vselect depvar ocand1 ocand2 ocand3, best

and will only run the minimum number of regressions necessary to obtain
the best models of 1, 2 and 3 covariates (plus the intercept) in terms of
in-sample RMSE, AIC and BIC.

. gsreg depvar ocand1 ocand2 ocand3, vselect fix(indepvar1)

will execute

. vselect depvar ocand1 ocand2 ocand3, best fixvar(indepvar1)

and will only run the minimum number of regressions necessary to obtain the best
models of 2, 3 and 4 covariates (plus the intercept) in terms of in-sample RMSE, AIC and BIC.
indepvar1 will be included in all regressions.

Back to General options

Back to Top

Examples of using dlags, ilags and lags

. gsreg depvar ocand1 ocand2, ncomb(3) dlags(1/4)

In this example there are two original candidate covariates (ocand1 and ocand2).
Dependent variable lags 1 to 4 will be added to the original candidates.
Therefore there will be 6 final candidates:

ocand1 ocand2 L2.depvar L1.depvar L3. depvar L4.depvar.

and 20 regressions must be estimated (combinations of size 3 taken from 6)

The same problem structure can be obtained by generating all lags before
executing gsreg and including them as original candidates:

. gen aux1= L1.depvar

. gen aux2= L2.depvar

. gen aux3= L3.depvar

. gen aux4= L4.depvar

. gsreg depvar ocand1 ocand2 aux1 aux2 aux3 aux4, ncomb(3)

. gsreg depvar ocand1 ocand2, ncomb(3) dlags(1 2 4(4)12)

In this example dependent variable lags 1,2,4,8 and 12 are included among
candidate covariates, increasing to 7 the final number of potential candidates:

ocand1 ocand2 L1.depvar L2.depvar L4.depvar L8.depvar L12.depvar

35 regressions will be estimated (combinations of size 3 taken from 7)

. gsreg depvar ocand1 ocand2, ncomb(3) ilags(1/4)

In this case, independent (explanatory) variable lags 1 to 4 will be added to the
original candidate covariates, obtaining the following final candidate list:

ocand1 ocand2 L1.ocand1 L2.ocand1 L3.ocand1 L4.ocand1 L1.ocand2 L2.ocand2 L3. ocand2 L4.ocand2

120 regressions must be estimated (combinations of size 3 taken from 10)

. gsreg depvar ocand1 ocand2, ncomb(3) lags(1 3))

In our final lag-structure example, lags 1 and 3 of dependent and explanatory variables
are included among candidates (now 8 candidates):

ocand1 ocand2 L1.depvar L3.depvar L1.ocand1 L3.ocand1 L1.ocand2 L3.ocand2

56 regressions will be estimated (combinations 3 taken from 8)

Back to Lag structure options

Back to Top

Examples of using fixvar

. gsreg depvar ocand1 ocand2, ncomb(1) fixvar(fixvar1 fixvar2)

will perform the following 2 regressions:

regress depvar ocand1 fixvar1 fixvar2

regress depvar ocand2 fixvar1 fixvar2

when using fixvar without the ncomb option, gsreg will also evaluate regressions
without any variable candidate covariate:

. gsreg depvar ocand1 ocand2, fixvar(fixvar1 fixvar2)

will perform the following 4 regressions:

regress depvar fixvar1 fixvar2

regress depvar ocand1 fixvar1 fixvar2

regress depvar ocand2 fixvar1 fixvar2

regress depvar ocand1 ocand2 fixvar1 fixvar2

Back to Fixed variable options

Back to Top

Examples of using schange, interactions, squares, cubic and fixinteractions

. gsreg depvar ocand1 ocand2, ncomb(1) schange(varschange)

will perform the following 6 regressions:

regress depvar ocand1

regress depvar ocand1 c.ocand1#varschange

regress depvar ocand1 c.ocand1#varschange varschange

regress depvar ocand2

regress depvar ocand2 c.ocand2#varschange

regress depvar ocand2 c.ocand2#varschange varschange

Note that it is also possible to test structural change by:

. gen aux1= c.ocand1#varschange

. gen aux2= c.ocand2#varschange

. gsreg depvar ocand1 ocand2 aux1 aux2 varschange, ncomb(1,3)

But this procedure will run 25 regressions (including the 6 of the first procedure).

. gsreg depvar ocand1 ocand2 ocand3, ncomb(2,3) interactions

will perform the following 14 regressions:

regress depvar ocand1 ocand2

regress depvar ocand1 ocand2 c.ocand1#c.ocand2

regress depvar ocand1 ocand3

regress depvar ocand1 ocand3 c.ocand1#c.ocand3

regress depvar ocand2 ocand3

regress depvar ocand2 ocand3 c.ocand2#c.ocand3

regress depvar ocand1 ocand2 ocand3

regress depvar ocand1 ocand2 ocand3 c.ocand1#c.ocand2

regress depvar ocand1 ocand2 ocand3 c.ocand1#c.ocand3

regress depvar ocand1 ocand2 ocand3 c.ocand2#c.ocand3

regress depvar ocand1 ocand2 ocand3 c.ocand1#c.ocand2 c.ocand1#c.ocand3

regress depvar ocand1 ocand2 ocand3 c.ocand1#c.ocand2 c.ocand2#c.ocand3

regress depvar ocand1 ocand2 ocand3 c.ocand1#c.ocand3 c.ocand1#c.ocand3

regress depvar ocand1 ocand2 ocand3 c.ocand1#c.ocand2 c.ocand1#c.ocand3
c.ocand2#c.ocand3

Note that it is also possible to evaluate this problem by generating
interactions before gsreg, including them as original gsreg candidates
and using the ncomb(2,6) option.

However, with this procedure gsreg will run 57 regressions
(including the 14 models of the first procedure).

. gsreg depvar ocand1 ocand2, ncomb(1,2) squares

will perform the following 8 regressions:

regress depvar ocand1

regress depvar ocand1 c.ocand1#c.ocand1

regress depvar ocand2

regress depvar ocand2 c.ocand2#c.ocand2

regress depvar ocand1 ocand2

regress depvar ocand1 ocand2 c.ocand1#c.ocand1

regress depvar ocand1 ocand2 c.ocand2#c.ocand2

regress depvar ocand1 ocand2 c.ocand1#c.ocand1 c.ocand2#c.ocand2

Note that it is also possible to examine the same problem by generating squares
before using gsreg, including them as original gsreg candidates and
using the option ncomb(1,4)

Notwithstanding, this procedure will run 15 regressions (including the 8 of the first procedure).

. gsreg depvar ocand1 ocand2, ncomb(1,2) squares cubic

will perform the following 15 regressions:

regress depvar ocand1

regress depvar ocand1 c.ocand1#c.ocand1

regress depvar ocand1 c.ocand1#c.ocand1 c.ocand1#c.ocand1#c.ocand1

regress depvar ocand2

regress depvar ocand2 c.ocand2#c.ocand2

regress depvar ocand2 c.ocand2#c.ocand2 c.ocand2#c.ocand2#c.ocand2

regress depvar ocand1 ocand2

regress depvar ocand1 ocand2 c.ocand1#c.ocand1

regress depvar ocand1 ocand2 c.ocand1#c.ocand1 c.ocand1#c.ocand1#c.ocand1

regress depvar ocand1 ocand2 c.ocand2#c.ocand2

regress depvar ocand1 ocand2 c.ocand2#c.ocand2 c.ocand2#c.ocand2#c.ocand2

regress depvar ocand1 ocand2 c.ocand1#c.ocand1 c.ocand2#c.ocand2

regress depvar ocand1 ocand2 c.ocand1#c.ocand1 c.ocand2#c.ocand2
c.ocand1#c.ocand1#c.ocand1

regress depvar ocand1 ocand2 c.ocand1#c.ocand1 c.ocand2#c.ocand2
c.ocand2#c.ocand2#c.ocand2

regress depvar ocand1 ocand2 c.ocand1#c.ocand1 c.ocand2#c.ocand2
c.ocand1#c.ocand1#c.ocand1 c.ocand2#c.ocand2#c.ocand2

Note that it is also possible to obtain these 15 regressions by generating squares
and cubes before gsreg, including them as original gsreg candidates and
using the option ncomb(1,6)

But this procedure will run 63 regressions (including the 15 of the first procedure).

. gsreg depvar ocand1 ocand2, ncomb(1,2) fixvar(fixvar1) fixinteractions

will perform the following 8 regressions:

regress depvar fixvar1 ocand1

regress depvar fixvar1 ocand1 c.ocand1#c.fixvar1

regress depvar fixvar1 ocand2

regress depvar fixvar1 ocand2 c.ocand2#c.fixvar1

regress depvar fixvar1 ocand1 ocand2

regress depvar fixvar1 ocand1 ocand2 c.ocand1#c.fixvar1

regress depvar fixvar1 ocand1 ocand2 c.ocand2#c.fixvar1

regress depvar fixvar1 ocand1 ocand2 c.ocand1#c.fixvar1 c.ocand2#c.fixvar1

Note that it is also possible to evaluate the same model selection problem by generating
interactions with fixvar before using gsreg, including them as original gsreg candidates
and using the option ncomb(1,4)

However, this procedure will run 15 regressions (including the 8 of the first procedure).

Back to Options for transformations and interactions

Back to Top

Examples of using outsample

Assume that we have 40 nonmissing observations

. gsreg depvar ocand1 ocand2, outsample(6)

Will perform all regressions using the first 34 observations. Post-estimation commands will
compute the rmse_out (out-of-sample root mean square error) for each regression using the last 6
observartions, storing them in the results database.

Back to Options for time series and panel data forecasts

Back to Top

Examples of using cmdest, cmdoptions, cmdstat and cmdiveq

. gsreg depvar ocand1 ocand2, cmdest(probit) cmdstat(r2_p)

will perform the following 3 regressions:

probit depvar ocand1

probit depvar ocand2

probit depvar ocand1 ocand2

and the Pseudo R2 of each estimation (e(r2_p)) will be saved in gsreg.dta

. gsreg depvar ocand1 ocand2, cmdoptions(robust)

will perform the following 3 regressions:

regress depvar ocand1, robust

regress depvar ocand2, robust

regress depvar ocand1 ocand2, robust

. gsreg depvar ocand1 ocand2, ncomb(1,2) cmdest(xtreg) cmdoptions(fe vce(robust))
cmdstat(sigma_u sigma_e rho r2_w r2_b r2_o)

will perform the following 3 regressions:

xtreg depvar ocand1, fe vce(robust)

xtreg depvar ocand2, fe vce(robust)

xtreg depvar ocand1 ocand2, fe vce(robust)

and the scalars stored in e(sigma_u), e(sigma_e), e(r2_p), e(rho), e(r2_w), e(r2_b) and e(r2_o)
will be saved in gsreg.dta xtreg

. gsreg depvar ocand1 ocand2, cmdest(ivregress liml) cmdiveq(ocand2= ivar1 ivar2)

will perform the following 3 regressions:

ivregress liml depvar ocand1

ivregress liml depvar ocand2 (ocand2= ivar1 ivar2)

ivregress liml depvar ocand1 ocand2 (ocand2= ivar1 ivar2)

(the first regression is equivalent to regress depvar ocand1)

. gsreg depvar ocand1 ocand2, cmdest(ivregress gmm) cmdiveq(ocand2= ivar1 ivar2)

will perform the following 3 regressions:

ivregress gmm depvar ocand1 (=ivar1 ivar2)

ivregress gmm depvar ocand2 (ocand2= ivar1 ivar2)

ivregress gmm depvar ocand1 ocand2 (ocand2= ivar1 ivar2)

. gsreg depvar ocand1 ocand2, cmdest(ivregress 2sls) cmdiveq(fixvar1 fixvar2= ivar1 ivar2) fixvar(fixvar1 fixvar2)

will perform the following 3 regressions:

ivregress 2sls depvar ocand1 (fixvar1 fixvar2= ivar1 ivar2)

ivregress 2sls depvar ocand2 (fixvar1 fixvar2= ivar1 ivar2)

ivregress 2sls depvar ocand1 ocand2 (fixvar1 fixvar2= ivar1 ivar2)

Back to Regressions command options

Back to Top

Examples of using aicbic, hettest, archlm, bgodfrey, durbinalt, dwatson, sktest, swilk, sfrancia and testpass

. gsreg depvar ocand1 ocand2, aicbic

will execute estat ic after each regression, saving values of the
Akaike and the Bayesian information criteria in gsreg.dta.

. gsreg depvar ocand1 ocand2, hettest

will execute estat hettest after each regression,
saving Breusch-Pagan / Cook-Weisberg (heteroscedasticity test) p-values in gsreg.dta.

. gsreg depvar ocand1 ocand2, hettest hettest_o(iid)

adds the option iid to estat hettest

. gsreg depvar ocand1 ocand2, aicbic archlm archlm_o(1 2 4)

adds the option lags(1 2 4) to estat archlm.
gsreg will save archlm test p-values for lags 1, 2 and 4 with varnames archlm1 archlm2 and archlm4

. gsreg depvar ocand1 ocand2, hettest archlm bgodfrey durbinalt sktest swilk sfrancia

after each regression, gsreg will execute:

estat hettest

estat archlm

estat bgodfrey

estat durbinalt

estat dwatson

estat sktest

estat swilk

estat sfrancia

saving each test p-values in gsreg.dta.

. gsreg depvar ocand1 ocand2, archlm archlm_o(lags(1 3)) durbinalt durbinalt_o(lags(1/4))
swilk swilk_o(noties) testpass(0.05)

after each regression, gsreg will execute:

estat archlm, lags(1 3)

estat durbinalt,lags(1/4)

estat dwatson

estat swilk, noties

each test p-value will be saved in gsreg.dta. Because of option testpass(0.05),
only regressions where all p-values are higher than 0.05 will be saved.

Back to Post-estimation options

Back to Top

Examples of using resultsdta, replace, double, compact, nindex and mindex

. gsreg depvar ocand1 ocand2 , resultsdta(myresults)

generates a results database named myresults.dta instead of gsreg.dta

. gsreg depvar ocand1 ocand2 , resultsdta(myresults) replace

will replaced myresults.dta if it has already been created in the ongoing working
directory. All results of myresults.dta will be stored with double precision

. gsreg depvar ocand1 ocand2 , compact resultsdta(myresults)

generates two results databases. myresults.dta without coefficients nor t-statistics,
and myresults_labels.dta with the name and position of each covariate.

. gsreg depvar ocand1 ocand2 , nindex(r_sqr_a)

is equivalent to

. gsreg depvar ocand1 ocand2

nindex=(r_sqr_a-mean(r_sqr_a))/sd(r_sqr_a) will be created and stored in gsreg.dta.
nindex will be used to sort models from highest to lowest values.

. gsreg depvar ocand1 ocand2 , nindex(1 r_sqr_a -.3 aic -.5 bic -1 rmse_out) aicbic
outsample(6)

will create nindex as a normalized polynomial function of r_sqr_a, aic, bic,
and rmse_out with weights 1, -0.3, -0.5 and -1, respectively.

. gsreg depvar ocand1 ocand2 ocand3, mindex(r_sqr_a) best(3)

will compute mindex=(r_sqr_a-mean(r_sqr_a))/sd(r_sqr_a) using the first 4
regression, deleting the worse (in terms of mindex). After that, mindex will be computed
again including the fifth regression and the best step one 3 regressions. The worse model among these new
4 regressions will be deleted. gsreg will repeat this procedure for all possible regressions, and
only the best 3 model results will be saved in gsreg.dta.

Back to Output options

Back to Top

Saved results

gsreg creates a .dta file with outcome information for all estimated
alternatives. By default it includes the following columns for each regression:

1) regression id (variable order)

2) covariate regression coefficients (named v_1_b, v_2_b… , etc.,
and labeled with the full covariate name plus the word “coeff.”)

3) coefficient t-statistics (named v_1_t, v_2_t…, etc., and labeled
with the full covariate name plus the word “tstat.”)

4) number of observations (variable obs)

5) number of covariates (variable nvar)

6) adjusted R2 (variable r_sqr_a)

7) in-sample root mean square error (variable rmse_in)

8) normalized linear combination of user selected (and weighted)
model selection criteria nindex (or mindex if this option is specified)

9) additional user specified statistics (if the cmdstat option is specified)

10) out-of-sample root mean square error (if outsample option is specified) and

11) residual test statistics (if specified).

When compact option is specified, regression coefficients and t-statistics
are omitted and replaced by a unique summary string variable as described in compact

In addition, gsreg shows on screen the best regression in terms of the user specified
mindex or mindex (or the adjusted R2 if these options are not specified).
Therefore, all this “best model” results (as scalars, macros, matrices and functions)
are also saved in e().

Back to Top

Authors

Pablo Gluzmann

CEDLAS-UNLP and CONICET

La Plata, Argentina

gluzmann@yahoo.com

Demian Panigo

CEIL-CONICET, UNM and UNLP

La Plata, Argentina

dpanigo@ceil-conicet.gov.ar

Back to Top

Also see

Article: Global Search Regression (GSREG): A new automatic model selection technique for cross-section, time series and panel data regressions, CEIL, Argentina

Help: estcom, regress, vselect