{smcl}
{* *! version 1.1 9apr2020 by Mead Over, CGD}{...}
{hline}
help for {hi:testallwith}{right:{hi:Version 1.1, 9Apr2020}}
{hline}
{viewerdialog testallwith "dialog testallwith"}{...}
{vieweralsosee "[R] test" "mansection R test"}{...}
{vieweralsosee "" "--"}{...}
{vieweralsosee "[R] anova" "help anova"}{...}
{vieweralsosee "[R] anova postestimation" "help anova_postestimation"}{...}
{vieweralsosee "[R] contrast" "help contrast"}{...}
{vieweralsosee "[R] lincom" "help lincom"}{...}
{vieweralsosee "[R] lrtest" "help lrtest"}{...}
{vieweralsosee "[R] nestreg" "help nestreg"}{...}
{vieweralsosee "[R] nlcom" "help nlcom"}{...}
{vieweralsosee "[R] testnl" "help testnl"}{...}
{viewerjumpto "Syntax" "testallwith##syntax"}{...}
{viewerjumpto "Description" "testallwith##description"}{...}
{viewerjumpto "Discussion" "testallwith##discussion"}{...}
{viewerjumpto "Options for testallwith" "testallwith##testallwith_options"}{...}
{viewerjumpto "Options for testparm" "testallwith##options_testparm"}{...}
{viewerjumpto "Examples" "testallwith##examples"}{...}
{viewerjumpto "Stored results" "testallwith##results"}{...}
{viewerjumpto "Author" "testallwith##author"}{...}
{p2colset 1 20 25 2}{...}
{p2col:{bf: testallwith} {hline 2}}Use Stata's {help testparm} to jointly test all coefficients which contain one or more specific variables{p_end}
{p2colreset}{...}
{marker syntax}{...}
{title:Syntax}
{p 8 17 2}
{cmd:testallwith}
{varlist}
[{cmd:,}
{opt j:oint(jvarlist)}
{help testallwith##testparm_options:{it:testparm_options}}
]
{marker testallwith_options}{...}
{synoptset 19 tabbed}{...}
{synopthdr:testallwith options}
{synoptline}
{synopt:{it:{help 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.{p_end}
{synopt:{opt j:oint(jvarlist)}}variable or variables included in all the coefficients to be jointly tested.
May include factor variables or time-series operators.{p_end}
{synoptline}
{p2colreset}{...}
{p 4 6 2}
{marker testparm_options}{...}
{synoptset 19 tabbed}{...}
{synopthdr:testparm_options}
{synoptline}
{synopt:{opt e:qual}}hypothesize that the coefficients are equal to each
other{p_end}
{synopt:{opth eq:uation(test##eqno:eqno)}}specify equation name or number for
which the hypothesis is tested{p_end}
{synopt:{opt nosvy:adjust}}compute unadjusted Wald tests for survey results
{p_end}
{synopt:{opt df(#)}}use F distribution with {it:#} denominator degrees of
freedom for the reference distribution of the test statistic; for survey data,
{it:#} specifies the design degrees of freedom unless {cmd:nosvyadjust} is
specified
{p_end}
{synoptline}
{p2colreset}{...}
{p 4 6 2}
{it:varlist} may contain factor variables and time-series operators including the binary factor variable operators "#" or "##";
{it:jvarlist} may not contain factor variables, time-series operators or the binary factor variable operators "#" or "##";
see {help fvvarlist} and {help tsvarlist}. {opt df(#)} does not appear in the dialog box.{p_end}
{marker description}{...}
{title:Description}
{pstd}
{cmd:testallwith} tests all the coefficients identified by {it:varlist} which involve
the variable or variables in {it:jvarlist}.{p_end}
{pstd}
{cmd:testallwith} extends Stata's {help testparm} by adding the option
{opt j:oint(jvarlist)}. Using this option, the user can more easily test
a joint hypothesis regarding all model coefficients involving a given variable or variables.
{help testallwith} accepts and passes on to {help testparm} all of {help testparm}'s standard options.{p_end}
{marker discussion}{...}
{title:Discussion}
{pstd}
Without Stata's factor variable syntax, a Stata estimation command like {help regress}
would not allow the same variable to appear more than once among the independent variables.
For example, in response to the command:{p_end}
{phang2}{cmd:. regress y x z x}{p_end}
{pstd}
Stata would simply omit the second occurrence of {it:x} from the estimated model.{p_end}
{pstd}
However, with Stata's {help fvvarlist:factor variables}
a variable can appear more than once among the independent variables.
For example, one can estimate the regression model{p_end}
{phang2}{cmd:. regress y x z c.x#c.z }{p_end}
{pstd}
or equivalently:{p_end}
{phang2}{cmd:. regress y c.x##c.z}{p_end}
{pstd}
In this model, the variable {it:x} appears once alone
and once interacted with the variable {it:z}.
In this interacted specification, to test the hypothesis
that the variable {it:x} contributes nothing
to the explanation of the variance of {it:y},
one must test the joint hypothesis that the coefficients of
both {it:x} and {it:c.x#c.z} are zero.{p_end}
{pstd}
In this simple example, constructing the joint test requires only
the following commands:{p_end}
{phang2}{cmd:. regress y c.x##c.z}{p_end}
{phang2}{cmd:. test x}{p_end}
{phang2}{cmd:. test c.x#c.z , accumulate}{p_end}
{pstd}
The same result can be achieved more efficiently by using this program
{cmd:testallwith} as follows:{p_end}
{phang2}{cmd:. regress y c.x##c.z}{p_end}
{phang2}{cmd:. testallwith c.x##c.z, joint(x) }{p_end}
{pstd}
By adding the option {cmd:equal}, we test whether the coefficients of {it:x}
and {it:c.x#c.z} are equal to each other.{p_end}
{phang2}{cmd:. regress y c.x##c.z}{p_end}
{phang2}{cmd:. testallwith c.x##c.z, joint(x) equal }{p_end}
{pstd}
In a complex model with many interactions, {cmd:testallwith} can save many lines
of code and also prevent coding mistakes.{p_end}
{pstd}To produce the required test, {cmd:testallwith} searches through the list
of coefficients in the previously estimated model that are associated with variables in the
user-specified {it:varlist} and constructs a list of the subset of coefficients which
contain one of the variables in the option {opt j:oint(jvarlist)}. It then
submits this subset of coefficients to {help testparm}.
By default, {help testparm} performs the joint test of
whether all of these coefficients are equal to zero. With the {opt equal} option,
{help testparm} performs the joint test of whether all the coefficients
are equal to each other.{p_end}
{marker options_testallwith}{...}
{title:Options for testallwith}
{phang}
{cmd: {it:{help varlist}}} The variable list immediately following the {cmd: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 {help varlist} is required.{p_end}
{phang}
{opt j:oint(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.
{cmd:testallwith} strips any {help fvvarlist:unary factor-variable operators} (such as i., c., 2., etc.)
and {help tsvarlist:time-series operators} (such as L., L1., D., etc.)
from the variable names before comparing the elements of {it:jvarlist} with the
coefficient names provided in {help varlist}.
The binary factor variable operators ("#" and "##") are retained.
If this {opt j:oint(jvarlist)} option is omitted, {cmd:testallwith} behaves like {help testparm}.{p_end}
{marker options_testparm}{...}
{title:Options for testparm}
{phang}
{opt e:qual} 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.
{phang}
{opt eq:uation(eqno)}
is relevant only for multiple-equation models, such as {cmd:mvreg},
{cmd:mlogit}, and {cmd:heckman}. It specifies the equation for which the
all-zero or all-equal hypothesis is tested. {cmd:equation(#1)} specifies
that the test be conducted regarding the first equation {cmd:#1}.
{cmd:equation(price)} specifies that the test concerns the equation named
{cmd:price}. See the help file for testparm {help test##eqno:here} for more details.
{phang}
{opt nosvy:adjust}
is for use with {opt svy} estimation commands; see
{manhelp svy_estimation 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
{bind:W/k ~ F(k,d)} rather than as
{bind:(d-k+1)W/(kd) ~ F(k,d-k+1)}, where {bind:k = the dimension} of the
test and {bind:d = the total} number of sampled PSUs minus the total number
of strata. When the {cmd:df()} option is used, it will override the
default design degrees of freedom.
{pstd}
The following option is available with {opt testallwith} but is not shown in
the dialog box:
{phang}
{opt df(#)} specifies that the F distribution with {it:#} denominator
degrees of freedom be used for the reference distribution of the test
statistic. The default is to use {cmd:e(df_r)} degrees of freedom or the
chi-squared distribution if {cmd:e(df_r)} is missing. With survey data,
{it:#} is the design degrees of freedom unless {cmd:nosvyadjust} is
specified.
{marker examples}{...}
{title:Examples after single-equation estimation}
{pstd}Setup{p_end}
{phang2}{cmd:. webuse census3}{p_end}
{phang2}{cmd:. regress brate c.medage##i.region}
{pstd}Test that coefficients on {cmd:2.region} and {cmd:3.region} are jointly
equal to 0{p_end}
{phang2}{cmd:. test (2.region=0) (3.region=0)}
{pstd}The following two commands are equivalent to the previous {cmd:test}
command{p_end}
{phang2}{cmd:. test 2.region = 0}{p_end}
{phang2}{cmd:. test 3.region = 0, accumulate}{p_end}
{pstd}Test that the coefficients on {cmd:2.region}, {cmd:3.region}, and
{cmd:4.region} are all 0; {cmd:testparm} understands a varlist{p_end}
{phang2}{cmd:. testparm i(2/4).region}
{pstd}Without the option {opt j:oint(jvarlist)}, {cmd:testallwith} behaves identically to {cmd:testparm}{p_end}
{phang2}{cmd:. testallwith i(2/4).region}
{pstd}To test the hypothesis that the median age explains none of the variance of birth rate,
one can use the {cmd:test} command four times, once for each of the variable combinations
containing {it:medage}, with the accumulate option on all but the first.{p_end}
{phang2}{cmd:. test medage = 0}{p_end}
{phang2}{cmd:. test 2.region#c.medage, accumulate}{p_end}
{phang2}{cmd:. test 3.region#c.medage, accumulate}{p_end}
{phang2}{cmd:. test 4.region#c.medage, accumulate}{p_end}
{pstd}Note that the above procedure jointly tests all the hypotheses
which include {it:medage} but excludes from the joint test all other coefficients.
The same joint test can be performed with one line of code like this.{p_end}
{phang2}{cmd:. test medage==0==2.region#c.medage==3.region#c.medage==4.region#c.medage}{p_end}
{pstd}
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 {it:medage} increases.
With the {cmd:testallwith} command, the same test can be performed
with the following single line of code.{p_end}
{phang2}{cmd:. testallwith c.medage##i.region, joint(medage)}{p_end}
{pstd}
Testing whether the dummy variable {it:region}
explains a statistically significant portion of the variance of
birth rate requires testing six joint hypotheses.
This test can be performed with {cmd:testallwith} as follows:{p_end}
{phang2}{cmd:. testallwith c.medage##i.region, joint(region)}{p_end}
{pstd}
Because {cmd:testallwith} strips unary factor variable operators
from the variable names in {it:jvarlist},
the results are identical with all of the following alternative
specifications for the {opt j:oint(jvarlist)} option.{p_end}
{phang2}{cmd:. testallwith c.medage##i.region, joint(i.region)}{p_end}
{phang2}{cmd:. testallwith c.medage##i.region, joint(1b.region)}{p_end}
{phang2}{cmd:. testallwith c.medage##i.region, joint(2.region)}{p_end}
{pstd}
Using the binary factor-variable operators in {it:jvarlist} does affect the results.
For example, with the binary operator "##", the {opt j:oint(jvarlist)} option
can request a test of all the coefficients identified by {help varlist}.
This behavior is rarely helpful as it typically produces the same results as {help testparm}.
To see this, note that the following three commands produce identical results.{p_end}
{phang2}{cmd:. testparm c.medage##i.region}{p_end}
{phang2}{cmd:. testallwith c.medage##i.region}{p_end}
{phang2}{cmd:. testallwith c.medage##i.region, joint(c.medage##i.region)}{p_end}
{pstd}
Similarly {cmd:testallwith}'s {opt j:oint(jvarlist)} option accepts the operator "#".
But the resulting output is typically identical to the output of {help testparm}.
{pstd}
In the above examples, you may substitute any single-equation estimation
command (such as {helpb clogit}, {helpb logistic}, {helpb logit}, and
{helpb ologit}) for {helpb regress}.
{marker results}{...}
{title:Stored results}
{pstd}
{cmd:testallwith} stores the following in {cmd:r()}:
{synoptset 15 tabbed}{...}
{p2col 5 15 19 2: Scalars}{p_end}
{synopt:{cmd:r(p)}}two-sided p-value{p_end}
{synopt:{cmd:r(F)}}F statistic{p_end}
{synopt:{cmd:r(df)}}test constraints degrees of freedom{p_end}
{synopt:{cmd:r(df_r)}}residual degrees of freedom{p_end}
{synopt:{cmd:r(dropped_i)}}index of {it:i}th constraint dropped{p_end}
{synopt:{cmd:r(chi2)}}chi-squared{p_end}
{synopt:{cmd:r(ss)}}sum of squares (test){p_end}
{synopt:{cmd:r(rss)}}residual sum of squares{p_end}
{synopt:{cmd:r(drop)}}{cmd:1} if constraints were dropped, {cmd:0} otherwise{p_end}
{p2col 5 15 19 2: Macros}{p_end}
{synopt:{cmd:r(varlist)}}variable list identifying coefficients in previous estimation{p_end}
{synopt:{cmd:r(jvarlist)}}variable(s) which must be included in all tested coefficients{p_end}
{synopt:{cmd:r(allwith)}}coefficients tested by {help testparm}{p_end}
{pstd}
{cmd:r(ss)} and {cmd:r(rss)} are defined only when {cmd:test} is used for
testing effects after {cmd:anova}.{p_end}
{p2colreset}{...}
{marker author}
{title:Author}
{p 4 8 20}
{browse "http://www.cgdev.org/content/experts/detail/10007/":Mead Over},
Center for Global Development, Washington, DC 20036 USA. Email:
{browse "mailto:mover@cgdev.org":MOver@CGDev.Org} if you observe any
problems.
{* Version history }
{* 1.0 6Apr2020 Uses code from test.sthlp version 1.2.3 19oct2017}{...}
{* 1.1 9Apr2020 Correct description of the -joint()- option to allow for fv and ts}{...}