unable to compute sqrt function due to error message [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



unable to compute sqrt function due to error message [closed]



Trying to do a one-sided Wald test based on a simple quantile regression on Stata 15.0


qreg volume if period == 2010



I want to test whether the coefficient (constant) of my qreg <= 10


qreg <= 10



Based on this post , I wrote this code:


local to_test = sign(_b[_cons]-1 )
display "H0: volume <=10 p-value=" ttail(r(df_r),`to_test' * sqrt(r(F)))



I end up with this error message:


H0: volume <=10 p-value=unknown function *sqrt()
r(133);



Why is this error message appear for a simple sqrt function?


sqrt



This question appears to be off-topic. The users who voted to close gave this specific reason:





Please provide us with a Minimal, Complete, and Verifiable example using Stata's dataex command so we can try to help you. Without sample data we cannot replicate anything.
– Pearly Spencer
Aug 7 at 20:24



dataex





I have more than 1M observations, how does it work then?
– user123456
Aug 7 at 20:37





help dataex to find out!
– Pearly Spencer
Aug 7 at 20:38


help dataex




1 Answer
1



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 displaying all of the pieces before doing the calculation that is giving you a problem is a good way to solve this.


display



Here's an example showing this on the cars dataset (an alternative to using dataex):


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

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard