Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to do one-sided test

    Hey guys,

    This is a simple question.
    I want to do a one-sided test to find out whether two coefficients from the same regression are the same.
    I googled this and get the following code, but I think there maybe something wrong with it, could you guys look into it and tell me why, thank you so much in advance!


    test t_m=o_m
    local sign_tmom = sign(t_m-o_m)
    display "H_0: t_m coef >= o_m coef. p-value ="1-ttail(r(df_r),`sign_tmom'*sqrt(r(F)))



  • #2
    You mean you googled, found this: http://www.stata.com/support/faqs/st...-coefficients/, and tried it? What went wrong? To me it looks like you are not accessing the coefficients correctly in the test line of code.

    Comment


    • #3
      The line
      Code:
      local sign_tmom = sign(t_m-o_m)
      is undoubtedly wrong. t_m and o_m are variables, taking on potentially different values in each observation in your data set. But local macro sign_tmom is a single number. When you define a local macro with a command that requires evaluation of variables, Stata uses the values of the variables in the first observation of the data set. In this context that makes no sense: sign_tmom will depend on the sort order of your data! That is undoubtedly the source of your problem.

      In any case, I don't see the need for anything nearly this complicated. The p-value of this 1-tailed test is simply half the pvalue of the 2-tailed version.

      Comment


      • #4
        The p-value of this 1-tailed test is simply half the pvalue of the 2-tailed version.
        I'll also add that, since the test is one-tailed, the sign of the difference has to be in the predicted direction.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 18.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          Yes, of course. Thanks, Richard, for presenting that additional qualification.

          Comment


          • #6
            I added that because my students have often made mistakes on such things! I give them a problem where the test statistic is large but they miss the fact that the sign is wrong. If I feel like being especially devious I'll give them a test stat that would be significant in a one-tailed test (if the sign was right) but not in a two-tailed test.
            -------------------------------------------
            Richard Williams, Notre Dame Dept of Sociology
            StataNow Version: 18.5 MP (2 processor)

            EMAIL: [email protected]
            WWW: https://www3.nd.edu/~rwilliam

            Comment


            • #7
              That is devious.

              Comment


              • #8
                Thank you all three of you, Clyde, Richard, and Dave.
                Actually, it should not be so complicated. After doing the regression, I just need to run
                "test p_m=o_m"
                Then, it gives me the two-sided and one-sided test results, right?

                Comment


                • #9
                  Originally posted by bruce fan View Post
                  Thank you all three of you, Clyde, Richard, and Dave.
                  Actually, it should not be so complicated. After doing the regression, I just need to run
                  "test p_m=o_m"
                  Then, it gives me the two-sided and one-sided test results, right?
                  Not to my knowledge, e.g.

                  Code:
                  . sysuse auto, clear
                  (1978 Automobile Data)
                  
                  . quietly reg weight length trunk
                  
                  . test length = trunk
                  
                   ( 1)  length - trunk = 0
                  
                         F(  1,    71) =   11.61
                              Prob > F =    0.0011
                  -------------------------------------------
                  Richard Williams, Notre Dame Dept of Sociology
                  StataNow Version: 18.5 MP (2 processor)

                  EMAIL: [email protected]
                  WWW: https://www3.nd.edu/~rwilliam

                  Comment


                  • #10
                    You can use lincom to get the signed t-statistic, and then go from there.

                    .ÿquietlyÿsysuseÿauto

                    .ÿquietlyÿregressÿweightÿlengthÿtrunk

                    .ÿlincomÿ_b[length]ÿ-ÿ_b[trunk]

                    ÿ(ÿ1)ÿÿlengthÿ-ÿtrunkÿ=ÿ0

                    ------------------------------------------------------------------------------
                    ÿÿÿÿÿÿweightÿ|ÿÿÿÿÿÿCoef.ÿÿÿStd.ÿErr.ÿÿÿÿÿÿtÿÿÿÿP>|t|ÿÿÿÿÿ[95%ÿConf.ÿInterval]
                    -------------+----------------------------------------------------------------
                    ÿÿÿÿÿÿÿÿÿ(1)ÿ|ÿÿÿÿ39.6695ÿÿÿ11.64357ÿÿÿÿÿ3.41ÿÿÿ0.001ÿÿÿÿÿ16.45288ÿÿÿÿ62.88612
                    ------------------------------------------------------------------------------

                    .ÿlincomÿ_b[trunk]ÿ-ÿ_b[length]

                    ÿ(ÿ1)ÿÿ-ÿlengthÿ+ÿtrunkÿ=ÿ0

                    ------------------------------------------------------------------------------
                    ÿÿÿÿÿÿweightÿ|ÿÿÿÿÿÿCoef.ÿÿÿStd.ÿErr.ÿÿÿÿÿÿtÿÿÿÿP>|t|ÿÿÿÿÿ[95%ÿConf.ÿInterval]
                    -------------+----------------------------------------------------------------
                    ÿÿÿÿÿÿÿÿÿ(1)ÿ|ÿÿÿ-39.6695ÿÿÿ11.64357ÿÿÿÿ-3.41ÿÿÿ0.001ÿÿÿÿ-62.88612ÿÿÿ-16.45288
                    ------------------------------------------------------------------------------

                    .

                    Comment


                    • #11
                      Thank you all so much, guys!!!!

                      Comment


                      • #12
                        Hi all,

                        I have a related question on performing a one-tailed test. I'm examining effects of unemployment on job security perceptions, and whether the effects differ by mental health status. I ran the two regressions below for the two separate mental health groups. How would I then perform a one-tailed test, to specifically test whether the negative coefficient for the first group (mh8_qn1==0) is larger in magnitude than that of the second group (mh8_qn1==1)?

                        Code:
                        xtreg job_sec_sat unemp_av6 i.sa4 i.year if entry3==0&mh8_qn1==0, fe i(id) cluster(id)
                        
                        xtreg job_sec_sat unemp_av6 i.sa4 i.year if entry3==0&mh8_qn1==1, fe i(id) cluster(id)
                        Below is a subsample of my data:

                        Code:
                        * Example generated by -dataex-. For more info, type help dataex
                        clear
                        input long id float year int sa4 byte job_sec_sat float(unemp_av6 entry3 mh8_qn1)
                        100003 2001 405 10  8.533333 1 0
                        100003 2002 405  9  6.816667 1 0
                        100003 2003 405  2  7.516666 1 0
                        100003 2004 405  4  5.366667 0 0
                        100003 2005 405  2       3.2 0 0
                        100003 2006 405  . 4.6666665 0 0
                        100003 2008 405  .  5.383333 0 0
                        100003 2009 405  8       2.5 0 0
                        100003 2011 405  .  3.383333 0 0
                        100003 2012 405  .         4 0 0
                        100003 2013 405  .  6.016667 0 0
                        100003 2014 403  .  7.266667 0 0
                        100003 2015 403  .       7.8 0 0
                        100003 2016 403  .  6.933333 0 0
                        100003 2017 403  .       6.8 0 0
                        100003 2018 403  .  6.416667 0 0
                        100010 2002 207  3       4.5 1 0
                        100010 2003 207  2  5.116667 1 0
                        100010 2004 207  1  3.466667 1 0
                        100010 2005 207  2 4.2166667 0 0
                        100010 2006 207  .       4.4 0 0
                        100010 2007 207  .  3.533333 0 0
                        100010 2008 206  .      4.75 0 0
                        100010 2009 206  .  5.733334 0 0
                        100010 2010 206  1 4.7166667 0 0
                        100010 2011 206  1  3.516667 0 0
                        100010 2012 208  5 4.4833336 0 0
                        100010 2013 208  1  4.766667 0 0
                        100010 2014 208  1      5.05 0 0
                        100010 2015 208  3  3.583333 0 0
                        100010 2016 208  .      3.65 0 0
                        100010 2017 208  2 4.2833333 0 0
                        100010 2018 208  4       3.2 0 0
                        100010 2019 208  5 4.0666666 0 0
                        100014 2001 106  7  9.333334 1 1
                        100014 2002 106  7  9.666666 1 1
                        100014 2003 106  9       5.8 1 1
                        100014 2004 106  7  5.716667 0 1
                        100014 2005 106  7  5.183333 0 1
                        100014 2006 106  8  3.866667 0 1
                        100014 2007 106  6 3.8166666 0 1
                        100014 2008 106  7 3.9333334 0 1
                        100014 2009 106  0       6.8 0 1
                        100014 2010 106  . 4.7333336 0 1
                        100014 2011 106  .  3.766667 0 1
                        100014 2012 106  .  2.866667 0 1
                        100014 2013 106  .  5.316667 0 1
                        100014 2014 106  .  7.566667 0 1
                        100014 2015 106  . 11.416667 0 1
                        100014 2016 106  .  5.066667 0 1
                        100014 2018 106  .       6.1 0 1
                        100014 2019 106  .  5.666667 0 1
                        100015 2001 106  7  9.333334 1 0
                        100015 2002 106  2  9.666666 1 0
                        100015 2003 106  8       5.8 1 0
                        100015 2004 106  9  5.716667 0 0
                        100015 2005 106 10  5.183333 0 0
                        100015 2006 106  9  3.866667 0 0
                        100015 2007 106  9 3.8166666 0 0
                        100015 2009 106 10       6.8 0 0
                        100015 2010 106 10 4.7333336 0 0
                        100015 2011 106 10  3.766667 0 0
                        100015 2012 106  9  2.866667 0 0
                        100015 2013 106  8  5.316667 0 0
                        100015 2015 106  9 11.416667 0 0
                        100015 2016 106 10  5.066667 0 0
                        100015 2017 106  8       4.8 0 0
                        100015 2018 106  8  6.166667 0 0
                        100015 2019 106  8  5.383333 0 0
                        100016 2007 111 10      4.85 1 0
                        100016 2008 111  9 4.7166667 1 0
                        100016 2009 111  9 4.7166667 1 0
                        100016 2010 111  9       4.5 0 0
                        100016 2011 111  9  4.116667 0 0
                        100016 2012 111  9      5.85 0 0
                        100016 2013 111  9  6.333333 0 0
                        100016 2014 111  9       6.7 0 0
                        100016 2015 111  9  6.766666 0 0
                        100016 2016 111  9      5.85 0 0
                        100016 2017 111 10  5.633333 0 0
                        100016 2018 111 10  6.033333 0 0
                        100016 2019 111 10  4.366667 0 0
                        100018 2001 507  .  7.133333 1 1
                        100018 2002 507  .  5.516666 1 1
                        100018 2003 507  .  6.766666 1 1
                        100018 2004 507  .       5.3 0 1
                        100018 2005 507  .      4.85 0 1
                        100018 2006 507  2 2.8166666 0 1
                        100018 2007 507  2  2.966667 0 1
                        100018 2008 507  3 3.6666665 0 1
                        100018 2009 507  4      5.45 0 1
                        100018 2010 507  5  5.433333 0 1
                        100018 2011 507  6 4.4333334 0 1
                        100018 2012 507  8  4.133333 0 1
                        100018 2013 507  7  5.266666 0 1
                        100018 2014 507  8  5.516666 0 1
                        100018 2015 507  8       5.7 0 1
                        100018 2016 507  7  6.316667 0 1
                        100018 2018 507  7  6.883333 0 1
                        100018 2019 507  9  7.016666 0 1
                        100019 2001 507  4  7.133333 1 1
                        100019 2002 507  3  5.516666 1 1
                        100019 2003 507  .  6.766666 1 1
                        100019 2004 507  4       5.3 0 1
                        100019 2005 507  6      4.85 0 1
                        100019 2006 507  6 2.8166666 0 1
                        100019 2007 507  7  2.966667 0 1
                        100019 2008 507  6 3.6666665 0 1
                        100019 2009 507  7      5.45 0 1
                        100019 2010 507  7  5.433333 0 1
                        100019 2011 507  6 4.4333334 0 1
                        100019 2012 507  4  4.133333 0 1
                        100019 2013 507  7  5.266666 0 1
                        100019 2014 507  8  5.516666 0 1
                        100019 2015 507  8       5.7 0 1
                        100019 2016 507  3  6.316667 0 1
                        100019 2017 507  3  6.133333 0 1
                        100019 2018 507  8  6.233334 0 1
                        100019 2019 503  9  4.266667 0 1
                        100020 2013 507  8  5.266666 1 1
                        100020 2014 507  8  5.516666 1 1
                        100020 2015 507  8       5.7 1 1
                        100020 2016 507  9  6.316667 0 1
                        100020 2017 507  8  6.133333 0 1
                        100020 2019 507  9  7.016666 0 1
                        100023 2001 317 10  5.666667 1 0
                        100023 2002 317 10 4.3166666 1 0
                        100023 2003 317 10  6.433333 1 0
                        100023 2004 317  .  4.733333 0 0
                        100023 2005 317 10      4.75 0 0
                        100023 2006 317  7  4.633333 0 0
                        100023 2007 317 10 2.3833332 0 0
                        100023 2008 317 10  3.416667 0 0
                        100023 2009 317 10  3.016667 0 0
                        100023 2010 317 10 3.3833334 0 0
                        100023 2011 317  9  4.233333 0 0
                        100023 2012 317 10      5.95 0 0
                        100023 2013 317  9      4.85 0 0
                        100023 2014 317  9  3.983333 0 0
                        100023 2015 317  8  5.883333 0 0
                        100023 2016 317  9       5.1 0 0
                        100023 2017 317 10  6.166667 0 0
                        100023 2018 317  8  6.166667 0 0
                        100023 2019 317  8       3.6 0 0
                        100024 2001 317 10  5.666667 1 0
                        100024 2002 317  9 4.3166666 1 0
                        100024 2003 317 10  6.433333 1 0
                        100024 2004 317 10  4.733333 0 0
                        100024 2005 317 10      4.75 0 0
                        100024 2006 317  9  4.633333 0 0
                        100024 2007 317  8 2.3833332 0 0
                        100024 2008 317 10  3.416667 0 0
                        100024 2009 317  9  3.016667 0 0
                        100024 2010 317  9 3.3833334 0 0
                        100024 2011 317  7  4.233333 0 0
                        100024 2012 317 10      5.95 0 0
                        100024 2013 317 10      4.85 0 0
                        100024 2014 317  9  3.983333 0 0
                        100024 2015 317  9  5.883333 0 0
                        100024 2016 317  9       5.1 0 0
                        100024 2017 317 10  6.166667 0 0
                        100024 2018 317 10  6.166667 0 0
                        100024 2019 317 10       3.6 0 0
                        100028 2001 104  8 10.416667 1 0
                        100028 2002 104  5 10.433333 1 0
                        100028 2004 104  9  8.883333 1 0
                        100028 2005 104  9  9.333333 0 0
                        100028 2006 104 10  9.833333 0 0
                        100028 2007 104 10  7.066667 0 0
                        100028 2008 104 10  7.133333 0 0
                        100028 2009 104 10 3.6833334 0 0
                        100028 2010 104  9  4.233333 0 0
                        100028 2012 104 10  6.683333 0 0
                        100028 2013 104 10  5.883333 0 0
                        100028 2014 104 10  7.283333 0 0
                        100028 2015 104  9  6.116667 0 0
                        100028 2016 104 10 4.3166666 0 0
                        100028 2017 104 10  8.766666 0 0
                        100028 2018 104  9  8.483334 0 0
                        100028 2019 104 10       4.5 0 0
                        100029 2001 123  5  8.983334 1 1
                        100029 2002 123  7      7.15 1 1
                        100029 2003 123  7  6.483334 1 1
                        100029 2004 123  6       8.5 0 1
                        100029 2005 123  8  5.533333 0 1
                        100029 2006 123  .  6.583333 0 1
                        100029 2007 123  .  6.133333 0 1
                        100029 2008 123  .  6.016666 0 1
                        100029 2009 123  .  8.233334 0 1
                        100029 2010 123  .  4.783333 0 1
                        100029 2011 123  9       4.7 0 1
                        100029 2012 123  5  5.866667 0 1
                        100029 2013 123  7  6.316667 0 1
                        100029 2014 123  6 4.7166667 0 1
                        100029 2015 123  6  6.283333 0 1
                        100029 2016 123  6  4.933333 0 1
                        100029 2017 123  6       5.6 0 1
                        100029 2018 123  .  4.116667 0 1
                        100029 2019 123  .         5 0 1
                        100030 2001 123 10  8.983334 1 0
                        end
                        label values job_sec_sat AJBMS
                        label def AJBMS 0 "[0] Totally dissatisfied", modify
                        label def AJBMS 10 "[10] Totally satisfied", modify

                        Comment


                        • #13
                          Ashani:
                          by splitting your regression in two (sub)regressions, you're trying to force the -fe- estimator to return a coefficient for a time-invariant predictors.
                          I would not sponsor your approach and would suggest to stick with one regression only and consider -xtreg,re- or The Stata Blog » Fixed effects or random effects: The Mundlak approach instead.
                          Kind regards,
                          Carlo
                          (StataNow 18.5)

                          Comment


                          • #14
                            To elaborate on Carlo's answer: the point of a fixed effects model is to look at changes within a person. That way you are more likely to compare like with like: you compare me with "previous me" and you with "previous you". The price you have to pay as that you loose the information you might obtain by comparing across individuals. That is deliberate: that information is considered suspect by users of fixed effects regression. By splitting the sample in two groups you are mixing the within and between approaches, in a way you don't want to do. So what you should do is:

                            Code:
                            xtreg job_sec_sat i.unemp_av6##i.mh8_qn1 i.sa4 i.year if entry3==0, fe i(id) cluster(id)
                            You expect the interaction term to be positive (being unemployed has a less negative effect for mh8_qn1==1 compared to mh8_qn==0). You can look directly to the regression output: if the interaction term is negative you reject your null. if the interaction term is positive, you multiply the p-value by 2, and compare that new p-value with your critical value.
                            ---------------------------------
                            Maarten L. Buis
                            University of Konstanz
                            Department of history and sociology
                            box 40
                            78457 Konstanz
                            Germany
                            http://www.maartenbuis.nl
                            ---------------------------------

                            Comment


                            • #15
                              Hi Carlo and Maarten,

                              Thank you very much for the feedback.

                              I had previously estimated the following regression which is similar to what you recommend, the only difference being that I also interacted sa4 and year with unemp_av6. Is that incorrect?

                              Code:
                              xtreg job_sec_sat mh8_qn1##(c.unemp_av6 i.sa4 i.year) if entry3==0, fe i(id) cluster(id)
                              Also, wouldn't I divide the p-value by two instead of multiplying it?

                              Comment

                              Working...
                              X