To perform a one-sided test, you need to perform the corresponding two-sided Wald test first. Then you can use the results to calculate the test statistic and p-value for the one-sided test.
Your code does not work because you are not doing the Wald test, so r(df_r) and r(F) are not defined. When you try to take the square root of a quantity that has not been calculated, Stata gives you a cryptic error. There are other problems, like having a 1 instead of a 10 in the sign calculation.
I think breaking up the problem and display
ing all of the pieces before doing the calculation that is giving you a problem is a good way to solve this.
Here's an example showing this on the cars dataset (an alternative to using dataex
):
. sysuse auto, clear
(1978 Automobile Data)
. qreg price weight length i.foreign, nolog
Median regression Number of obs = 74
Raw sum of deviations 71102.5 (about 4934)
Min sum of deviations 54411.29 Pseudo R2 = 0.2347
------------------------------------------------------------------------------
price | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
weight | 3.933588 1.328718 2.96 0.004 1.283543 6.583632
length | -41.25191 45.46469 -0.91 0.367 -131.9284 49.42456
|
foreign |
Foreign | 3377.771 885.4198 3.81 0.000 1611.857 5143.685
_cons | 344.6489 5182.394 0.07 0.947 -9991.31 10680.61
------------------------------------------------------------------------------
. local sign_cons = sign(_b[_cons] - 10)
. display "`sign_cons'"
1
. display r(df_r)
.
. display r(F)
.
. test _b[_cons] = 10
( 1) _cons = 10
F( 1, 70) = 0.00
Prob > F = 0.9487
. display r(df_r)
70
. display r(F)
.00416983
. display "Ho: _cons <= 10 p-value = " ttail(r(df_r),`sign_cons'*sqrt(r(F)))
Ho: _cons <= 10 p-value = .47434855