*! version 1.1 9apr2020 by Mead Over, CGD

help for testallwithVersion 1.1, 9Apr2020

testallwith -- Use Stata's testparm to jointly test all coefficients which contain one or more specific variables

Syntax

testallwith
varlist
[,
joint(jvarlist)
testparm_options
]

testallwith options

varlist variables identifying coefficients
in the previously estimated model from among which tested coefficients
are to be selected.
May include factor variables or time-series operators.

joint(jvarlist) variable or variables included in all the coefficients to be jointly tested.
May include factor variables or time-series operators.

testparm_options

equal hypothesize that the coefficients are equal to each
other

equation(test##eqno:eqno) specify equation name or number for
which the hypothesis is tested

nosvyadjust compute unadjusted Wald tests for survey results

df(#) use F distribution with # denominator degrees of
freedom for the reference distribution of the test statistic; for survey data,
# specifies the design degrees of freedom unless nosvyadjust is
specified

varlist may contain factor variables and time-series operators including the binary factor variable operators "#" or "##";
jvarlist may not contain factor variables, time-series operators or the binary factor variable operators "#" or "##";
see fvvarlist and tsvarlist. df(#) does not appear in the dialog box.

Description

testallwith tests all the coefficients identified by varlist which involve
the variable or variables in jvarlist.

testallwith extends Stata's testparm by adding the option
joint(jvarlist). Using this option, the user can more easily test
a joint hypothesis regarding all model coefficients involving a given variable or variables.
testallwith accepts and passes on to testparm all of testparm's standard options.

Discussion

Without Stata's factor variable syntax, a Stata estimation command like regress
would not allow the same variable to appear more than once among the independent variables.
For example, in response to the command:

. regress y x z x

Stata would simply omit the second occurrence of x from the estimated model.

However, with Stata's factor variables
a variable can appear more than once among the independent variables.
For example, one can estimate the regression model

. regress y x z c.x#c.z

or equivalently:

. regress y c.x##c.z

In this model, the variable x appears once alone
and once interacted with the variable z.
In this interacted specification, to test the hypothesis
that the variable x contributes nothing
to the explanation of the variance of y,
one must test the joint hypothesis that the coefficients of
both x and c.x#c.z are zero.

In this simple example, constructing the joint test requires only
the following commands:

. regress y c.x##c.z

. test x

. test c.x#c.z , accumulate

The same result can be achieved more efficiently by using this program
testallwith as follows:

. regress y c.x##c.z

. testallwith c.x##c.z, joint(x)

By adding the option equal, we test whether the coefficients of x
and c.x#c.z are equal to each other.

. regress y c.x##c.z

. testallwith c.x##c.z, joint(x) equal

In a complex model with many interactions, testallwith can save many lines
of code and also prevent coding mistakes.

To produce the required test, testallwith searches through the list
of coefficients in the previously estimated model that are associated with variables in the
user-specified varlist and constructs a list of the subset of coefficients which
contain one of the variables in the option joint(jvarlist). It then
submits this subset of coefficients to testparm.
By default, testparm performs the joint test of
whether all of these coefficients are equal to zero. With the equal option,
testparm performs the joint test of whether all the coefficients
are equal to each other.

Options for testallwith

varlist The variable list immediately following the testallwith command
should contain a list of all variables identifying coefficients
in the previously estimated model from among which tested coefficients
are to be selected. A convenient choice is to include here
the entire "right-hand-side" of the estimated model.
May include factor variables or time-series operators.
The varlist is required.

joint(jvarlist) A list of the variable or variables
which must be included in all the coefficients to be jointly tested.
May include factor variables or time-series operators.
testallwith strips any unary factor-variable operators (such as i., c., 2., etc.)
and time-series operators (such as L., L1., D., etc.)
from the variable names before comparing the elements of jvarlist with the
coefficient names provided in varlist.
The binary factor variable operators ("#" and "##") are retained.
If this joint(jvarlist) option is omitted, testallwith behaves like testparm.

Options for testparm

equal tests that the variables
appearing in varlist, which also appear in the previously fit model,
are equal to each other rather than jointly equal to zero.

equation(eqno)
is relevant only for multiple-equation models, such as mvreg,
mlogit, and heckman. It specifies the equation for which the
all-zero or all-equal hypothesis is tested. equation(#1) specifies
that the test be conducted regarding the first equation #1.
equation(price) specifies that the test concerns the equation named
price. See the help file for testparm here for more details.

nosvyadjust
is for use with svy estimation commands; see
[SVY] svy estimation. It specifies that the
Wald test be carried out without the default adjustment for the design
degrees of freedom. That is, the test is carried out as
W/k ~ F(k,d) rather than as
(d-k+1)W/(kd) ~ F(k,d-k+1) , where k = the dimension of the
test and d = the total number of sampled PSUs minus the total number
of strata. When the df() option is used, it will override the
default design degrees of freedom.

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

df(#) specifies that the F distribution with # denominator
degrees of freedom be used for the reference distribution of the test
statistic. The default is to use e(df_r) degrees of freedom or the
chi-squared distribution if e(df_r) is missing. With survey data,
# is the design degrees of freedom unless nosvyadjust is
specified.

Examples after single-equation estimation

Setup

. webuse census3

. regress brate c.medage##i.region

Test that coefficients on 2.region and 3.region are jointly
equal to 0

. test (2.region=0) (3.region=0)

The following two commands are equivalent to the previous test
command

. test 2.region = 0

. test 3.region = 0, accumulate

Test that the coefficients on 2.region, 3.region, and
4.region are all 0; testparm understands a varlist

. testparm i(2/4).region

Without the option joint(jvarlist), testallwith behaves identically to testparm

. testallwith i(2/4).region

To test the hypothesis that the median age explains none of the variance of birth rate,
one can use the test command four times, once for each of the variable combinations
containing medage, with the accumulate option on all but the first.

. test medage = 0

. test 2.region#c.medage, accumulate

. test 3.region#c.medage, accumulate

. test 4.region#c.medage, accumulate

Note that the above procedure jointly tests all the hypotheses
which include medage but excludes from the joint test all other coefficients.
The same joint test can be performed with one line of code like this.

. test medage==0==2.region#c.medage==3.region#c.medage==4.region#c.medage

However, coding either of the above is tedious
when there are four hypotheses and
becomes more so as the number of terms
involving the variable medage increases.
With the testallwith command, the same test can be performed
with the following single line of code.

. testallwith c.medage##i.region, joint(medage)

Testing whether the dummy variable region
explains a statistically significant portion of the variance of
birth rate requires testing six joint hypotheses.
This test can be performed with testallwith as follows:

. testallwith c.medage##i.region, joint(region)

Because testallwith strips unary factor variable operators
from the variable names in jvarlist,
the results are identical with all of the following alternative
specifications for the joint(jvarlist) option.

. testallwith c.medage##i.region, joint(i.region)

. testallwith c.medage##i.region, joint(1b.region)

. testallwith c.medage##i.region, joint(2.region)

Using the binary factor-variable operators in jvarlist does affect the results.
For example, with the binary operator "##", the joint(jvarlist) option
can request a test of all the coefficients identified by varlist.
This behavior is rarely helpful as it typically produces the same results as testparm.
To see this, note that the following three commands produce identical results.

. testparm c.medage##i.region

. testallwith c.medage##i.region

. testallwith c.medage##i.region, joint(c.medage##i.region)

Similarly testallwith's joint(jvarlist) option accepts the operator "#".
But the resulting output is typically identical to the output of testparm.

In the above examples, you may substitute any single-equation estimation
command (such as clogit, logistic, logit, and
ologit) for regress.

Stored results

testallwith stores the following in r():

Scalars

r(p) two-sided p-value

r(F) F statistic

r(df) test constraints degrees of freedom

r(df_r) residual degrees of freedom

r(dropped_i) index of ith constraint dropped

r(chi2) chi-squared

r(ss) sum of squares (test)

r(rss) residual sum of squares

r(drop) 1 if constraints were dropped, 0 otherwise

Macros

r(varlist) variable list identifying coefficients in previous estimation

r(jvarlist) variable(s) which must be included in all tested coefficients

r(allwith) coefficients tested by testparm

r(ss) and r(rss) are defined only when test is used for
testing effects after anova.

Author

Mead Over,
Center for Global Development, Washington, DC 20036 USA. Email:
MOver@CGDev.Org if you observe any
problems.