0

I need help conducting a hypothesis test to compare the coefficients for two of my explanatory variables in Stata. My null and alternative are:

null: β1=β2 vs alt: β1>β2.

So far I have used the command test to compare the two estimates. However, I don't know if I can modify test to fit my alt.

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
hardy
  • 3
  • 1

1 Answers1

2

To do one-sided tests on coefficients, you can

  • perform the corresponding two-sided test on the coefficients (or sometimes just look at the regression output)
  • use the results to get a p-value for the one-sided test. This step can done in two ways, either by using using the reverse cumulative Student's t distribution directly or by doing some arithmetic on the p-value from the two-sided test.

If you are testing differences of coefficients (since a=b is equivalent to a-b=0), the approach is the same as doing single coefficients. You need to do a two-sided test of the difference:

sysuse auto, clear
regress price mpg weight 
gen high_mpg    = mpg>20
gen high_weight = weight>3000
reg price high_mpg high_weight foreign 

/* Test H0: diff = 0 */
test high_weight - foreign = 0
display r(p)
display r(F)

/* The ttail approach works when the actual coefficient difference is positive or negative */
local sign_diff = sign(_b[high_weight] - _b[foreign] - 0)
display "p-value for Ha: diff < 10 = " ttail(r(df_r),`sign_diff'*sqrt(r(F)))
display "p-value for Ha: diff > 10 = " 1-ttail(r(df_r),`sign_diff'*sqrt(r(F)))

/* Can also do it by hand like this if diff is positive (like above) */
display "p-value for Ha: diff < 0 = " r(p)/2 
display "p-value for Ha: diff > 0 = " 1-r(p)/2 

/* if difference is negative, you can still do it by hand */
/* but need to flip the p-value division rules since we are on the other */
/* side of the distribution */
/* Test H0': diff2 = -400 */ 
test high_mpg - foreign  = -400
local sign_diff2 = sign(_b[high_mpg] - _b[foreign] + 400)
display "p-value for Ha': diff2 < 0 = " ttail(r(df_r),`sign_diff2'*sqrt(r(F)))
display 1-r(p)/2
display "p-value for Ha': diff2 > 0 = " 1-ttail(r(df_r),`sign_diff2'*sqrt(r(F)))
display r(p)/2

If your test returns r(chi2) instead of r(F), you need to swap the ttail part for

normal(`sign_diff'*sqrt(r(chi2)))
dimitriy
  • 9,077
  • 2
  • 25
  • 50
  • Thank you for your reply Dimitriy, it's been very helpful. I have 2 things I would like to clarify if that's okay. 1) I ran the test command and got a p-value of 0.0001 from r(p), which gave me a corresponding p-value of approx .9999 since I want to test Ha diff>0 do I interpret this as not being able to reject the null in favour of alt that the difference is positive? 2) My test returned r(chi2) instead. So by swapping it do you mean I should use r(chi2) instead of r(F) or do I need to reestimate using the F-distribution? – hardy Jun 14 '20 at 14:34
  • (1) Yes, the rhyming mnemonic is "reject the null when the p-value is small," since the p-value corresponds to the probability of observing a difference at least this large under the null. You can find lots of good examples at [CV site](https://stats.stackexchange.com/), which is a better place for stats questions that don't involve programming. – dimitriy Jun 14 '20 at 19:17
  • On (2), you want to swap out the `ttail` part for -normal(`sign_diff'*sqrt(r(chi2)))-. – dimitriy Jun 14 '20 at 19:20