|
Size: 2217
Comment: Killing Econometrics page
|
← Revision 8 as of 2025-11-06 20:44:52 ⇥
Size: 3364
Comment: Notes
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| = Stata Test = | = Stata test = |
| Line 3: | Line 3: |
| The '''`test`''' command performs [[Statistics/WaldTest|Wald tests]]. | '''`-test-`''' performs [[Statistics/WaldTest|Wald tests]] on regression coefficients. See also [[Stata/TestParm|-testparm-]]. |
| Line 13: | Line 15: |
| The `test` command supports one type of syntax when called as itself, and a second type of syntax when called as `testparm`. | Consider this test on one coefficient: {{{ . use https://www.stata-press.com/data/r18/census3 (1980 Census data by state) . regress brate medage c.medage#c.medage i.region [snip] . test 3.region = 0 ( 1) 3.region = 0 F( 1, 44) = 3.47 Prob > F = 0.0691 }}} The [[Statistics/FTest|F-statistic]] of the hypothesis is 3.47, corresponding to a significance level of about 0.07. In most settings, this would be considered insufficient to reject the null hypothesis: the factor is not significant. Consider this joint test on a parameter: {{{ . test (2.region = 0) (3.region = 0) (4.region = 0) ( 1) 2.region = 0 ( 2) 3.region = 0 ( 3) 4.region = 0 F( 3, 44) = 8.85 Prob > F = 0.0001 }}} The F-statistic of the joint hypotheses is 8.85, corresponding to a significance level very close to 0. This is a strong basis to reject the joint null hypotheses: the variable is significant. |
| Line 17: | Line 47: |
| === Test Syntax === | === Coefficient Names === |
| Line 19: | Line 49: |
| Test that one or more coefficients are equal to 0. | To list the coefficient names that `-test-` can reference, add the '''`coeflegend`''' option to an estimation command. |
| Line 22: | Line 52: |
| // Coefficients represented by variables test x1 test x1 x2 |
. webuse nhanes2l (Second National Health and Nutrition Examination Survey) |
| Line 26: | Line 55: |
| // Coefficients represented by factor indicators test x1.a }}} |
. regress bpsystol i.diabetes##c.age c.age#c.age i.hlthstat, coeflegend [snip] -------------------------------------------------------------------------------- bpsystol | Coefficient Legend ---------------+---------------------------------------------------------------- diabetes | Diabetic | -2.789364 _b[1.diabetes] age | .0436002 _b[age] | diabetes#c.age | Diabetic | .158519 _b[1.diabetes#c.age] | c.age#c.age | .0060262 _b[c.age#c.age] | hlthstat | Very good | .829615 _b[2.hlthstat] Good | 2.438839 _b[3.hlthstat] Fair | 4.179397 _b[4.hlthstat] Poor | 3.100577 _b[5.hlthstat] | _cons | 111.268 _b[_cons] -------------------------------------------------------------------------------- |
| Line 30: | Line 78: |
| Test that two coefficients are equal to each other. | . test (_b[age] = 0) (_b[c.age#c.age] = 0) |
| Line 32: | Line 80: |
| {{{ // Coefficients represented by variables test x1 = x2 |
( 1) age = 0 ( 2) c.age#c.age = 0 |
| Line 36: | Line 83: |
| // Coefficients represented by factor indicators test x1.a = x2.a }}} If used after a multi-equation model was run, by default, these tests check that coefficients are equal to 0 in all equations. To specify an equation, try: {{{ // Test equal to 0 test [y1]x1 test [y1]x1 [y2]x1 // Test equal to each other test [y1]x1 = [y2]x1 // Alternative syntax: test [y1=y2]: x1 }}} Similarly, to test all coefficients between two equations, try: {{{ // Test all coefficients for equality to each other test [y1=y2] // Or, if not all coefficients are common to both equations, try: test [y1=y2], common }}} Linear transformations can also be tested for equality. {{{ test x1 + x2 = 4 test 2*x1 = 3*x2 |
F( 2, 10326) = 1140.12 Prob > F = 0.0000 |
| Line 73: | Line 89: |
| === TestParm Syntax === | === Expressions === |
| Line 75: | Line 91: |
| Test that one or more coefficients are equal to 0. | Expressions are interpreted by these patterns, where `a` and `b` represent ''sub-expressions'' and `1` represents a scalar value. |
| Line 77: | Line 93: |
| {{{ // Coefficients represented by variables testparm x1 |
* `a`: hypothesis that a coefficient is equal to 0 * `a = 1`: hypothesis that a coefficient is equal to a scalar value * `a = b`: hypothesis that coefficients are equal to each other |
| Line 81: | Line 97: |
| // Standard varlist syntax applies testparm x1-x9 testparm x* |
Expressions can be delimited with parentheses. |
| Line 85: | Line 99: |
| // Coefficients represented by indicators testparm i.x1 |
Sub-expressions can be variable names, factor indicators, or linear combinations. For example: |
| Line 88: | Line 101: |
| // Coefficients represented by interactions of indicators testparm i.x1#i.x2 }}} |
* `x1`: variable `x1` * `2.a`: factor indicator 2 of `a` * `2*x1`: linear combination of a variable * `x1+x2`: linear combination of variables |
| Line 92: | Line 106: |
| Test that two or more coefficients are equal to each other. {{{ testparm i.x1, equal }}} If used after a multi-equation model was run, by default, these tests check that coefficients are equal to 0 in all equations. To specify an equation, try: {{{ // Test equal to 0 testparm i.x1, equation(y1) // Test equal to each other testparm i.x1, equal equation(y1) }}} |
If a multiple-equation model has been run, use the `[equation]variable` syntax to specify the hypothesis. For example, `test [y1]x1=[y3]x1`. |
| Line 114: | Line 114: |
| [[https://www.stata.com/manuals/rtest.pdf|Stata manual for test]] | [[https://www.stata.com/manuals/rtest.pdf|Stata manual for -test-]] |
Stata test
-test- performs Wald tests on regression coefficients.
See also -testparm-.
Contents
Usage
Consider this test on one coefficient:
. use https://www.stata-press.com/data/r18/census3
(1980 Census data by state)
. regress brate medage c.medage#c.medage i.region
[snip]
. test 3.region = 0
( 1) 3.region = 0
F( 1, 44) = 3.47
Prob > F = 0.0691The F-statistic of the hypothesis is 3.47, corresponding to a significance level of about 0.07. In most settings, this would be considered insufficient to reject the null hypothesis: the factor is not significant.
Consider this joint test on a parameter:
. test (2.region = 0) (3.region = 0) (4.region = 0)
( 1) 2.region = 0
( 2) 3.region = 0
( 3) 4.region = 0
F( 3, 44) = 8.85
Prob > F = 0.0001The F-statistic of the joint hypotheses is 8.85, corresponding to a significance level very close to 0. This is a strong basis to reject the joint null hypotheses: the variable is significant.
Coefficient Names
To list the coefficient names that -test- can reference, add the coeflegend option to an estimation command.
. webuse nhanes2l
(Second National Health and Nutrition Examination Survey)
. regress bpsystol i.diabetes##c.age c.age#c.age i.hlthstat, coeflegend
[snip]
--------------------------------------------------------------------------------
bpsystol | Coefficient Legend
---------------+----------------------------------------------------------------
diabetes |
Diabetic | -2.789364 _b[1.diabetes]
age | .0436002 _b[age]
|
diabetes#c.age |
Diabetic | .158519 _b[1.diabetes#c.age]
|
c.age#c.age | .0060262 _b[c.age#c.age]
|
hlthstat |
Very good | .829615 _b[2.hlthstat]
Good | 2.438839 _b[3.hlthstat]
Fair | 4.179397 _b[4.hlthstat]
Poor | 3.100577 _b[5.hlthstat]
|
_cons | 111.268 _b[_cons]
--------------------------------------------------------------------------------
. test (_b[age] = 0) (_b[c.age#c.age] = 0)
( 1) age = 0
( 2) c.age#c.age = 0
F( 2, 10326) = 1140.12
Prob > F = 0.0000
Expressions
Expressions are interpreted by these patterns, where a and b represent sub-expressions and 1 represents a scalar value.
a: hypothesis that a coefficient is equal to 0
a = 1: hypothesis that a coefficient is equal to a scalar value
a = b: hypothesis that coefficients are equal to each other
Expressions can be delimited with parentheses.
Sub-expressions can be variable names, factor indicators, or linear combinations. For example:
x1: variable x1
2.a: factor indicator 2 of a
2*x1: linear combination of a variable
x1+x2: linear combination of variables
If a multiple-equation model has been run, use the [equation]variable syntax to specify the hypothesis. For example, test [y1]x1=[y3]x1.
