*! version November 2, 2023 @ 12:29:16 UK

Title

twostep -- Two-step multilevel analysis

Syntax

twostep
macroid
[,
twostep-options
]:
microcmd
||
macrocmd

microcmd may be an estimation command such as regress, logit, etc., or

microcpr
depvar
indepvars
[if] [in]
[weight]

microdfb
depvar
indepvars
[if] [in]

macrocmd may be one of the following special purpose commands

avplot
macrodepvar macroindepvars
[if] [in]
[ using filename ]
[, avplot-options ]

dot
macrodepvar macroindepvars
[if] [in]
[ using filename ]
[, dot-options ]

edv
macrodepvar macroindepvars
[if] [in]
[ using filename ]
[, edv-options ]

cprplot
macrodepvar macroindepvars
[if] [in]
[ using filename ]
[, cprplot-options ]

regby
macrodepvar macroindepvars
[if] [in]
[ using filename ]
[, regby-options ]

mk2nd
macrodepvar macroindepvars
[if] [in]
[ using filename ]
[, mk2nd-options ]

macrodepvar macroindepvars
[if] [in]
[ using filename ]
[, microcpr-options | microdfb-options ]

or an arbitrary Stata command with the syntax

cmd
macrodepvar macroindepvars
[if] [in]
[, options ]

The latter utilization will be referred to as "fallback mode" in the
following.

avplot-options
method(arg) Options allowed for the EDV-model twostep edv

regopts(options) Options allowed for twoway line

scopts(options) Options allowed for twoway scatter

twoway options Options allowed for graph twoway

cprplot-options
method(arg) Options allowed for the EDV-model twostep

lowessopts(options) Options allowed for twoway lowess

regopts(options) Options allowed for twoway line

scopts(options) Options allowed for twoway scatter

twoway options Options allowed for graph twoway

dot-options
ciopts(options) Options allowed for twoway rcap

scopts(options) Options allowed for twoway scatter

twoway options Options allowed for graph twoway

edv-options
method(arg) Method for macro-level estimation

regress options Options allowed for regress

microcpr-options
allopts(options) Options allowed for twoway line

byopts(options) Options allowed for graph, by()

lowessopts(options) Options allowed for twoway lowess

regopts(options) Options allowed for twoway line

scopts(options) Options allowed for twoway scatter

twoway options Options allowed for graph twoway

microdfb-options
box(options) Options allowed for barlook_options

marker(options) Options allowed for marker_options and marker_label_options

boxlook_options Boxlook options of graph box

over_options Over sub_opts of graph box

other_options Some other options of graph box

regby-options
allopts(options) Options listed in line option

byopts(options) Options allowed for graph, by()

discrete(varlist) Treat macro-level vars as discrete

nquantiles(#) Grouping for macro-level varlist

regopts(options) Options listed in line option

unitby(varlist) Additional grouping on micro-level varlist

twoway options Options allowed for graph twoway

mk2nd-options
clear preexisting data will be be replaced

twostep-options
stats(namelist) Additional stats for macro-level

macroid refers to a varlist identifying macro-level
units in the dataset in memory. Both depvar and indepvars refer to
variables in the dataset in memory. macrodepvar refers to
an implied name of regression coefficients or other model statistics
(see below). macroindepvars refer to the names of
macro-level variables. Both indepvars and macroindepvars may
contain factor variables; see fvvarlist.

macrodepvar is either an implied name
of an estimated regression coefficient or of a summary statistic. The implied name
of the estimated regression coefficients is specified by adding _b_ before
the name of the variable of interest in indepvars. In case of factor
variables one must add _b_#_ with # referring to the category of
the respective variable. We suggest using twostep ... || mk2nd _all
for checking the implied coefficient names in case of factor
variables with interactions. Other model statistics may be specified by adding
the statistics names with the prefix _stat_.
The statistic must have been specified in the twostep-option
stats(name).

macroindepvars are macro-level
variables. The variables must be constant within
macroid. Moreover the variables must exist, either in the pooled
micro-level data in memory or in the file specified by using.

using filename refers to a dataset holding
macro-level variables. In this dataset, macroid must uniquely
identify the observations. If using is not specified, the
macro-level variables must exist in the dataset in memory.

weights are allowed for microcmd if the estimation command
being used allows weights. In the case of microcpr, fweights,
aweights and pweights are allowed; see help weight.
weights are not allowed for microdfb and for any macrocmd.

Description

twostep is a bundle of programs intended to ease multilevel
analysis with the two-step approach. The two-step approach to multilevel
analysis involves estimating a parameter of interest in a micro-level
dataset (e.g. individuals) separately for each category of a macro
level variable (e.g. countries, states, schools, etc.). The two-step
approach can be used as an alternative to one-step approaches that
estimate all parameters in a pooled dataset taking into account the
hierarchical structure of the data (e.g. cluster-robust standard
errors, fixed- and random intercept models, or multilevel
mixed-effects regression). The two-step approach offers an
attractive alternative to the one-step approach if the number of
observations at the macro-level is small (e.g. < 50) and the number of
micro-level observations within each macro-level unit is large (see Achen
2005). Additionally, it may be used for
exploratory data analysis of multilevel data, for graphical display of
modeling results, or to check model assumptions of the one-step approach.

Most of the methods implemented in twostep are wrappers
for a series of standard Stata commands. The idea of twostep is
to offer several related methods with very similar commands to ease
analyzing hierarchical data interactively.

The following examples highlight the consistent design of
twostep using a subset of the forth round of the European
Quality of Life Survey (EQLS). The EQLS is a survey based on probability
samples of respondents from all European Union member countries and
hence a typical example of an international comparative dataset. A
special feature of the EQLS is that it also contains a number of macro-level
variables in the micro-level dataset. The following examples
use gdppcap, i.e. the gross-domestic-product in purchasing power
parities, as the macro-level characteristic.

twostep provides the following procedures:

o Estimated-Dependent-Variable Model (EDV-Model) as
described e.g. by Lewis and Linzer (2005). In this
model, the estimated regression coefficients of models fitted
separately for each macro-level unit using the micro-level data are
fed into a linear regression at the macro-level as dependent variable.
The macro-level regression is weighted by an inverse function
of the uncertainty of the model estimates. For example,

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || edv _b_hhinc gdppcap

estimates an EDV-model regressing the micro-level coefficients
for hhinc (household income) on the macro-level variable gdppcap
(the gross domestic product per capita). See section EDV-model for variants of the EDV-model.

o Horizontally labeled dot charts of coefficients with
confidence intervals as shown by Bowers and Drake (2005, figure
1). For example,

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || dot _b_hhinc gdppcap

creates a plot of all estimated micro-level coefficients for
hhinc in a dot chart, where the coefficients are sorted by the field
rank of the macro-level variable gdppcap. See section
Dot chart for variants of this plot.

o Component-plus-residual plots for all micro-level
models. This plot is a straightforward generalization of the
multivariate scatter plots proposed by Bowers and Drake
(2005, figure 2). For example,

. use eqls2003_twostep, clear

. twostep cntry: microcpr lsat hhinc i.sex || _b_hhinc gdppcap

creates the component-plus-residual plots of the coefficient
for hhinc for each macro-level unit (i.e. country). Every plot
shows the regression line for all observations in comparison to
regression lines and non-parametric regression lines (LOWESS) for the
respective macro-level unit. The plots are sorted by the
field rank of the macro-level variable gdppcap. See section
microcpr for variants of this plot. Also see
cprplot for a general description of the component-plus-residual plot.

o Box plots for DFBETAs of a specified micro-level
covariate for all micro-level models. This plot is usefull to
detect influential data points in the micro-level regressions. For
example,

. use eqls2003_twostep, clear

. twostep cntry: microdfb lsat hhinc i.sex || _b_hhinc gdppcap

creates box plots of the DFBETAs for the coefficient of hhinc
for each macro-level unit (i.e. country). The plots are sorted by the
field rank of the macro-level variable gdppcap. See section microdfb for variants of this plot. Also see
dfbeta for a general description of the
DFBETAs.

o Added-variable plots for the EDV regression
models. This plot is a straightforward application
of the standard added-variable plot for the EDV-model. For example,

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || avplot _b_hhinc gdppcap

creates an added-variable plot for the EDV-model
estimated above.
See section avplot for variants of this
plot. Also see
avplot for a general description of the added-variable plot plot.

o Component-plus-residual plots for the EDV regression
models. This plot is a straightforward application
of the standard component-plus-residual plot for the EDV-model. For example,

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || cprplot _b_hhinc gdppcap

creates a component-plus-residual plot for the EDV-model
estimated above. The plot contains the regression line as well as a
non-parametric regression line (LOWESS). See section
cprplot for variants of this plot.

o Plots of grouped predictions of micro-level models as
proposed by Bowers and Drake (2005, figure
3) -- we call this a "regby plot" in the following. For example,

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || regby _b_hhinc gdppcap

uses a regby plot to show regression lines based on the
coefficient of hhinc for the micro-level regressions calculated
separately for all macro-level units. Macro-level units
are grouped into categories derived from the macro-level variable
gdppcap. See section regby for
variants of this plot.

o Distributional diagnostic plots for the estimated
regression coefficients of the micro-level regression models. These
plots are particularly useful to inspect the distributional
assumptions for random intercept and/or random-effects (mixed-)models. For
example,

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || pnorm _b_hhinc

creates a standardized normal plot for the estimated regression
coefficients of hhinc. Instead of pnorm all commands described in
diagnostic plots can be used.

o Fallback mode: Besides the methods described,
twostep has a fallback mode that allows the specification of
arbitrary Stata commands for analyzing the micro-level regression
coefficients (or other model statistics) at the macro-level. For example,

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || summarize _b_hhinc, detail

calculates the mean and standard deviation of the
micro-level regression coefficients for hhinc. The fallback mode
assumes that the Stata command corresponds to a standard syntax with a
varlist immediately following the command. The first variable
of varlist must be macrodepvar.

o Creation of macro-level dataset As a second fallback
mode, twostep can be utizlized for creating a macro-level dataset
holding regression coefficients of the micro-level regressions. This is
useful for two-step multilevel analyses that cannot be
performed with any of the implemented methods. For example,

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || mk2nd _all gdppcap

creates a dataset holding all the macro-unit specific micro
level regression coefficients, their standard errors and the macro
level variable gdppcap. The standalone command edv can
be used for estimating an EDV-model for each of the coefficents,
including the constant:

. edv _b_cons gdppcap

. edv _b_hhinc gdppcap

. edv _b_2_sex gdppcap

The following description of procedures is arranged in
alphabetical order.

Macro-level added-variable plot

twostep
macroid : microcmd
depvar
indepvars [, micro-options] ||
avplot
macrodepvar
macroindepvars
[ using filename ]
[, macro-options ]

micro-options
regress options Options allowed for microcmd

macro-options
scopts(options) Options allowed for twoway scatter

regopts(options) Options allowed for twoway line

twoway options Options allowed for graph twoway

The terms of the command are defined as in the general syntax
above. macrodepvar is used to specify the outcome of an EDV-model
and macroindepvars is used to specify the independent variables of an
EDV-model. The first variable of macroindepvars defines the
variable for which the added-variable plot is drawn.

avplot options

scopts(options) defines the appearance of the symbols for the
macro-level observations. options can be any of the options
allowed for twoway scatter. Among these options,
msymbol(), msize(), and mcolor() may be particularly
useful.

regopts(options) defines the appearance of the regression
line. options can be any of the options allowed for
twoway line. Among these options, lcolor(), lwidth(), and
msize() may be particularly useful.

twoway options options allowed for graph twoway.

avplot examples

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || avplot _b_hhinc gdppcap

. twostep cntry: regress lsat hhinc i.sex age [pw=wght] || avplot _b_hhinc gdppcap urbanpop

. twostep cntry: regress lsat hhinc i.sex || avplot _b_hhinc gdppcap, regopts(lcolor(none))

removes the linear fit from the graph.

Macro-level component-plus-residual plot

twostep
macroid : microcmd
depvar
indepvars [, micro-options] ||
cprplot
macrodepvar
macroindepvars
[ using filename ]
[, macro-options ]

micro-options
regress options Options allowed for microcmd

macro-options
scopts(options) Options allowed for twoway scatter

regopts(options) Options allowed for twoway line

lowessopts(options) Options allowed for twoway lowess

twoway options Options allowed for graph twoway

The terms of the command are defined as in the general syntax
above. macrodepvar is used to specify the outcome
and macroindepvars is used to specify the independent variables of an
EDV-model. The first variable of macroindepvars defines the
variable for which the component-plus-residual plot is shown.

cprplot options

scopts(options) defines the appearance of the symbols for the
macro-level observations. options can be any of the options
allowed for twoway scatter. Among these options,
msymbol(), msize(), and mcolor() may be particularly
useful.

regopts(options) defines the appearance of the regression
line. options can be any of the options allowed for
twoway line. Among these options, lcolor(), lwidth(), and
msize() may be particularly useful.

lowess(options) defines the appearance of the lines for the
non-parametric regression line. options can be any of the options
allowed for twoway line. Among these options, lcolor(),
lwidth(), and msize() may be particularly useful.

twoway options options allowed for graph twoway.

cprplot examples

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || cprplot _b_hhinc gdppcap

. twostep cntry: regress lsat hhinc i.sex || cprplot _b_hhinc gdppcap urbanpop

. twostep cntry: regress lsat hhinc i.sex || cprplot _b_hhinc gdppcap, regopts(lcolor(none))

erases the linear fit from the graph.

Dot-chart

twostep
macroid [, twostep-options ] : microcmd
depvar
indepvars [, micro-options] ||
dot
macrodepvar
[ macroindepvars ]
[ using filename ]
[, macro-options ]

twostep
stats(namelist) Additional model statistics

micro-options
regress options Options allowed for regress

macro-options
scopts(options) Options allowed for twoway scatter

ciopts(options) Options allowed for twoway rcap

twoway options Options allowed for graph twoway

The terms of the command are defined as in the general syntax
above. macrodepvar is used to specify the coefficient (or statistic)
to be shown in the dot-chart. macroindepvars is used to
define the order used for the vertical axis of the chart.

dot options

stats(namelist) defines the model statistics to be stored
together with the model coefficients. names can be any scalar
stored by the estimation command used for the micro-level
regression. For example, to store the R-square of a
linear regression model, use stats(r2).

scopt(options) defines the appearance of the dots. options
can be any of the options allowed for twoway scatter. Among
these options, msymbol(), msize(), and
mcolor() may be particularly useful.

ciopt(options) defines the appearance of the confidence
intervals (if present). options can be any of the options allowed for
twoway rcap. Among these options, lcolor(),
lwidth(), and msize() may be particularly useful.

twoway options options allowed for graph twoway.

dot examples

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || dot _b_hhinc

. twostep cntry: regress lsat hhinc i.sex || dot _b_hhinc gdppcap

. twostep cntry: regress lsat hhinc i.sex || dot _b_hhinc gdppcap, scopts(mcolor(red) ms(S)) ciopts(lwidth(0))

just to show how scopts() and ciopts() work.

. twostep cntry, stats(r2): regress lsat hhinc i.sex || dot _stat_r2

to show R-squared instead of coefficients.

. twostep cntry, stats(r2): regress lsat hhinc i.sex || dot _stat_r2, title(R2 by country) xtitle(R2) ysize(5)

an example with twoway options.

EDV-model

twostep
macroid : microcmd
depvar
indepvars [, micro-options] ||
edv
macrodepvar
macroindepvars
[ using filename ]
[, macro-options ]

or

edv
macrodepvar
macroindepvars
[, macro-options ]

micro-options
regress options Options allowed for regress

macro-options
method(arg) One of ols, wls, fgls1, fgls2

regress options Options allowed for regress

The terms of the command are defined as in the general syntax
above. macrodepvar is used to specify the outcome of an EDV-model
and macroindepvars is used to specify the independent variables of an
EDV-model.

Technical Note: In addition to regress, twostep
allows a variation estimation commands for microcmd. Hence, it is
technically possible to run the EDV-model on micro-level regression
coefficients of logit, probit, xtreg or
other. Since the statistical properties of the EDV-model have only
been shown for linear regression, twostep issues a warning
message when the micro-level command is not regress.

edv Options

method(name) defines the function used to weight the
observations in the EDV-model. name can be any of
fgls1 (default), fgls2, ols, and wls.

fgls1 weights the observations using the FGLS approach
proposed by Hanushek (1974); also see Lewis
and Linzer (2005:351-352). This is the default
if method() is not specified.

fgls2 weights the observations using the FGLS approach
proposed by Lewis and Linzer (2005:352-354).

ols does not apply weights to the second level
regression; Bryan and Jenkins (2016:footnote
4) recommend this; also see Donald and Lang
(2007: 223-224).

wls weights the observations by the reciprocal value of
the regression coefficient's variance, as proposed by Saxonhouse
(1976).

regress option options allowed for regress.

edv examples

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || edv _b_hhinc gdppcap

. twostep cntry: regress lsat hhinc age if sex == 1 || edv _b_hhinc gdppcap if !mi(eu15)

. twostep cntry: regress lsat hhinc i.sex || edv _b_hhinc gdppcap, method(ols) vce(robust)

to regress _b_hhinc on gdppcap without any weights at all

Micro-level component-plus-residual plot

Component-plus-residual plots for all micro-level
regression models are created with the micro-level command
microcpr. The general syntax is:

twostep
macroid

: microcpr depvar
indepvars
[, micro-options ]
||
macrodepvar
macroindepvars
[ using filename ]
[, macro-options ]

micro-options
regress options Options allowed for regress

macro-options
allopts(options) Options allowed for twoway line

regopts(options) Options allowed for twoway line

lowessopts(options) Options allowed for twoway line

scopts(options) Options allowed for twoway scatter

twoway options Options allowed for graph twoway

The terms of the command are defined as in the general syntax
above. macrodepvar is used here to specify
the name of the micro-level independent variable for
which the component-plus-residual plot is drawn.
macroindepvars is used to specify the order
of the plots.

Note: With microdfb, twostep is used without a macro-level command.

microcpr options

allopts(options) defines the appearance of regression line
for all micro-level models. options can be
any of the options allowed for twoway line. Among these options,
lcolor(), and lwidth() may be particularly
useful.

regopts(options) defines the appearance of macro specific
regression lines. options can be any of the options allowed for
twoway line. Among these options, lcolor(), and
lwidth() may be particularly usefull.

lowessopts(options) defines the appearance of macro specific
LOWESS lines. options can be any of the options allowed for
twoway line. Among these options, lcolor(), and
lwidth() may be particularly useful.

scopt(options) defines the appearance of the dots. options
can be any of the options allowed for twoway scatter. Among
these options, msymbol(), msize(), and
mcolor() may be particularly useful.

twoway options options allowed for graph twoway.

microcpr examples

. use eqls2003_twostep, clear

. twostep cntry: microcpr lsat hhinc i.sex || _b_hhinc

. twostep cntry: microcpr lsat hhinc i.sex || _b_hhinc gdppcap, scopts(ms(i)) allopts(lwidth(0))

to show macro specific regression and LOWESS lines, only.

DFBETA box plots for micro-level regression

Box plots of DFBETAs for all the micro-level
regression models are shown with the micro-level command
microdfb. The general syntax is:

twostep
macroid

: microdfb depvar
indepvars
[, micro-options ]
||
macrodepvar
macroindepvars
[ using filename ]
[, macro-options ]

micro-options
regress options Options allowed for regress

macro-options
box(options) barlook_options

marker(options) marker_options and marker_label_options

boxlook_options Boxlook options of graph box

other_options Additional options for graph box

The terms of the command are defined as in the general syntax
above. macrodepvar is used here to specify
the name of the independent variable of the micro-level models for
which the box plots of DFBETAs are drawn.
macroindepvars is used to specify the order
of the plots.

Note: With microdfb, twostep is used without macro-level command.

microdfb options

box(option) defines the appearance of the boxes. Any options
described in barlook_options can be used.

marker(options) defines the appearance of the marker for the
outliers. Any of the options described in marker_options and
marker_label_options can be used.

boxlook_options are any other of the boxlook_options
described in graph_box, except box.

other_options are some but not all of the options
described in graph_box. Technically, twostep passes all
options invoked to the box-plot. Some of the options, however, may be
in conflict with the current settings. In that case they ma either be ignored or
an error message will be issued.

microdfb examples

. use eqls2003_twostep, clear

. twostep cntry: microdfb lsat hhinc i.sex || _b_hhinc

. twostep cntry: microdfb lsat hhinc i.sex || _b_hhinc, marker(mlab(id) mlabpos(12))

to label the outliers.

Regby plot

twostep
macroid: microcmd depvar
indepvars [, micro-options] ||
regby
macrodepvar
macroindepvars
[ using filename ]
[, macro-options ]

micro-options
regress options Options allowed for microcmd

macro-options
allopts(options) Options listed in line option

byopts(options) Options allowed for graph, by()

discrete(varlist) Treat macro-level vars as discrete}

nquantiles(#) Grouping for macro-level varlist

regopts(options) Options listed in line option

unitby(varlist) Additional grouping on micro-level varlist

twoway options Options allowed for graph twoway

The terms of the command are defined as in the general syntax
above. macrodepvar is used to specify the
name of the coefficients used to define the slopes to be shown.
macroindepvars is used to define the
groups into which the specified macro-level units are grouped into.

regby options

allopts(options) defines the appearance of the lines in the
background of the sub-graphs. By default, regby draws a
background graph showing the regression line for all
macro-level units. This is intended to ease the comparison of each
subgroup with the other groups. However, the background graph can be considered a
nuisance in some situations and perhaps also is a matter of
taste. The background options allows the user to fine tune the
background graph, including a complete removal. options can be
any of the options listed in line option. Specify
allopts(lcolor(none)) to remove the background graph.

byopts(options) is used to define the overall
arrangement of the regby plot. options can be any of the
options allowed for graph by. Among these options,
rows(#), cols(#), and compact may be particularly
useful. We stress that the overall titles, subtitles, notes, and
captions should be specified here.

discrete(varlist) turns off the default categorization
of the variables in the varlist. Assuming continuous macro-level
variables to be the standard case, regby dichotomizes all the
macro-level variables by default. This automatic grouping is turned
off for all variables in the varlist. Note that the option allows
arbitrary groupings of the macro-level variables by feeding custom-made
variables into discrete(). See option nquantiles() for
other means to change the default categorization of macro-level
variables.

regopts(options) defines the appearance of the regression
lines. options can be any of the line options. The line
options lcolor() and lwidth() may be particularly
useful.

nquantiles(#) defines the number of groups created from
each of the macro-level variables. Assuming
continuous macro-level variables to be the standard case,
regby dichotimizes all the macro-level variables by
default. The option nquantiles(#) can be used to define the
number of groups to be created. Specifically, #
defines the number of quantiles by which the
macro-level variables are grouped. nquantiles(4), for example, groups macro-level
variables into four groups using the 1st, 2nd, and 3rd
quartile. See option disrete() for other means to control
the grouping.

unitby(varlist) allows additional grouping
based on micro-level variables. In presence of microby(), the
micro-level regression models are estimated separately for each
combination of the macro-level identifier and the variables
specified. The microby-variables are then also used for the definition
of the various sub-graphs.

twoway options options allowed for graph twoway.

regby examples

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || regby _b_hhinc gdppcap

. twostep cntry: regress lsat hhinc i.sex || regby _b_hhinc gdppcap urbanpop

. twostep cntry: regress lsat hhinc i.sex || regby _b_hhinc gdppcap, allopts(lcolor(none))

removes the background graph.

. twostep cntry: regress lsat hhinc age || regby _b_hhinc gdppcap, nq(4) microby(sex) byopts(cols(2)) ysize(8)

demonstrates some flexibility.

. twostep cntry: regress lsat hhinc age || regby _b_hhinc gdppcap eu15, nq(4) discrete(eu15) byopts(cols(2)) ysize(8)

shows an example for the usage of option discrete.

Macro-level datasets

twostep
macroid
[ , stats(name) ]
: microcmd depvar
indepvars [, micro-options] ||
mk2nd
macrodepvar
[ macroindepvars ]
[ using filename ]
[ , clear ]

twostep-options
stats(namelist) Additional Stats for macro-level

micro-options
model options Options allowed for microcmd

mk2nd-options
clear Okay to replace the data in memory

The terms of the command are defined as in the general syntax
above. macrodepvar is used to specify the
name of the coefficients to be stored. Here However,
macrodepvar may also be _all, in which case all coefficients
and standard errors are stored. macroindepvars is used to specify the names
of macro-level variables to be stored.

mk2nd options

stats(namelist) defines the model statistics to be stored
together with the model coefficients. names can be any scalar
stored by the estimation command used for the micro-level
regression. To store the R-square of a
linear regression model, for example, use stats(r2).

clear specifies that it is okay to replace the data in
memory, even though the current data have not been
saved to disk.

mk2nd examples

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || mk2nd _b_hhinc gdppcap

creates a macro-level dataset holding the (micro-level) estimated regression
coefficients of hhinc, their standard errors, the numbers of
observations, as well as the macro-level variable
gdppcap.

. use eqls2003_twostep, clear

. twostep cntry: regress lsat hhinc i.sex || mk2nd _all gdppcap

as before, but with all the micro-level regression
coefficients/standard errors.

. use eqls2003_twostep, clear

. twostep cntry, stats(r2 r2_a ll): regress lsat hhinc i.sex || mk2nd _all gdppcap

as before, but including selected statistics of the micro-level regression models.

Acknowledgements

We wish to thank Kekeli Abbey, Lena Hipp and Armin Sauermann
for beta testing. We are very gratefull to Stephen Jenkins, editor of
the Stata Journal, and to two anonymous reviewers for their rigourous
advices, which made the program much better. Ulrich Kohler wishes to
thank the participants of summer's 2017 and winter's 2020/21
multilevel seminar for commenting earlier versions of twostep.

Authors

Ulrich Kohler, University of Potsdam

email: ukohler@uni-potsdam.de

web: https://www.uni-potsdam.de/soziologie-methoden/

Johannes Giesecke, Humboldt-University Berlin

email: johannes.giesecke@hu-berlin.de"

web: https://www.sowi.hu-berlin.de/de/lehrbereiche/empisoz/a-z/giesecke

References

Achen, C., 2005. Two-Step Hierarchical
Estimation: Beyond Regression Analysis. Political Analysis, 13,
447-456.

Bowers, J. and K. Drake, 2005. EDA for
HLM: Visualization when Probabilistic Inference Fails. Political
Analysis, 13, 301-326.

Bryan, M.L., and S. Jenkins, 2016. Multilevel Modeling of Country Effects: A
Cautionary Tale. Supplementary Material. European Sociological Review, 32(1), 3-22.

Donald, S.G., and K. Lang, 2008. Inference
with difference-in-difference and other panel data. Review of
Econometrics and Statistics, 89(2), 221-233.

Hanushek, E., 1974. Efficient Estimators for Regressing Regression Coefficients. The
American Statistician, 28(1), 66-67.

Lewis, F.B. and D.A. Linzer, 2005. Estimating
Regression Model in Which the Dependent Variable is Based on
Estimates. Political Analysis, 13, 345-364.

Saxonhouse, G. R., 1976. Estimated Parameters as Dependent Variables. American
Economic Review, 66(1), 178-183.