Announcement

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

  • one tailed test in special cases

    Hi
    I want to report t or z stats for one-sided instead of two-sided test after markov switching model. I did the following.

    Code:
    mswitch dr gdp, switch(inf) states(2) varswitch vce(oim) 
    
    local sign_inf1 = sign(_b[State1:inf])
    
    display "H_0: coef<=0  p-value = " 1-normal(`sign_inf1'*sqrt(r(chi2)))
    
    
    display "H_0: coef>=0  p-value = " normal(`sign_agg_inf1'*sqrt(r(chi2)))
    however, I get an error messge;

    H_0: coef<=0 p-value = unknown function *sqr()

    Can someone help to fix this please? Thanks

  • #2
    Is it the extra _agg_ in the fourth line?

    Comment


    • #3
      Dimitriy V. Masterov Not really, that was a typo here only.

      ​​​​​​​I am still getting the same error message

      Comment


      • #4
        I am now thinking that it has to be something related to z stats or the function normal() as the markov switching model report z stats and not t stats. However, the chi2 should be appropriate here.

        I hope someone can help
        Last edited by Mike Kraft; 22 Aug 2023, 01:34.

        Comment


        • #5
          Your code shows sqrt() -- which is certainly the name of a Stata function -- but the error message you report refers to sqr() -- which isn't, although it is a name used in some other software for a square root function.

          I think we need a report based on fewer typos. Giving us a data example could help, so that we could try to replicate the problem.

          I am with Dimitriy V. Masterov: my guess is that Stata can't see the local macro, either (1) because it was never defined anywhere, or (2) because you are running code in chunks, and the definition of the local is not in the same chunk as its reference. The latter problem (2) is discussed in more detail at https://journals.sagepub.com/doi/pdf...36867X20931028

          I doubt that this is do with statistical principles, although that is a visceral guess.

          Comment


          • #6
            Thanks Nick!

            First, you are right that I was running this in chunks and once I have done it all at once I no longer get the error message. Thanks for that.
            However, I still get no results when I do it as below even though there is no error any more. I have include a dataex and hope to get some further assistance. The exact code is also below.

            Code:
            * Example generated by -dataex-.    To    install:    ssc    install    dataex
            clear
            input float(gdp inf)
            -.15912275  -.10412808
            .09266312  -.17734697
            .06238146   -.3140645
            .1003086  -.53705096
            .04127723   .09137875
            .007405024    .0515528
            -.05980303    .1870726
            .15197453    .3187126
            .033147737    .1194568
            .02404358   .14203024
            .04470645   .15694696
            -.04389818    .2072565
            -.06813001   .24772313
            .017472947    .2618746
            -.06573346    .2799356
            .013654263   .22160913
            -.10910688   .10532077
            -.17863147   .18036287
            .02453373   .21417046
            .1825736  -.03991305
            .13831255  -.11554485
            -.03320964  -.13180627
            .04898705  -.04673392
            .11328086   .07538252
            .01889895    .3225786
            .03804962    .2806678
            .0012684565    .1650907
            .00506812   .19543704
            -.016614793   .11020956
            .021917466   .13569182
            .005860911   .12736659
            -.06374294   .08917537
            .14155625   .07377382
            .0861522   .14549617
            -.0784217   .16771397
            .03825453    .2488849
            .05727483   .32833245
            .12533192   .21308812
            -.005435857    .2434506
            .0893553   .16136655
            .003562767    .2178454
            .12037104  .011492976
            .1610871  .010114562
            -.05054996    .0534085
            .02007691  .007441879
            -.05139175     .143525
            .05405565   .08732025
            -.09967183 .0019972546
            .006232464  -.14016491
            .07415348   -.1579013
            .17100805  -.10785072
            .08661003  -.16655563
            .1205432  -.01793599
            .013095206   .10022017
            .022359865     .197051
            -.05547845   .21640334
            -.033144854    .3509707
            .11636598   .22351266
            -.005237876  .026628705
            .13082045   -.0126893
            .0543263  -.06140576
            .014636938  -.08690438
            .077632  -.07033621
            .12550417  -.14485532
            .09166063 -.018134134
            .03389942   .01555846
            -.016710065   .04606963
            .14817744 -.005178612
            .006486706   .11476161
            .12696432  .015480446
            -.30903    .1985257
            .1709989   .10256623
            -.006295912   .19777167
            .019477904    .3036929
            .035165526   .09804793
            .068203904   .22583315
            .11065657    .0808415
            .09418894  .035322268
            -.008102294  -.20921397
            -.034057897  -.14305758
            .08513564  -.13258266
            -.1077248  -.07293752
            .006028487  .029134983
            .15087596  -.13096577
            .06198982   -.1241697
            .02405199  -.18267107
            -.027157733  -.18206313
            .11741457  -.17480834
            .007060129   .04594216
            -.002882732   .08498085
            .05845396   .13505565
            .03787044   .12421904
            .030932084   .19650497
            .04677445  .015070876
            -.0026416525   .15442483
            .0273554    .1565506
            -.016175805   .11130662
            .04624455    .1462939
            -.04106052   .24631456
            .08386634   .27426964
            end

            Code:
            mswitch dr gdp, switch(inf) states(2) varswitch vce(oim) 
            
            local sign_inf1 = sign(_b[State1:inf])
            
            display "H_0: coef<=0  p-value = " 1-normal(`sign_inf1'*sqrt(r(chi2)))
            
            display "H_0: coef>=0  p-value = " normal(`sign_inf1'*sqrt(r(chi2)))

            Comment


            • #7
              You have solved one problem, so excellent. I have never used mswitch so will leave #6 open to people who have or who can see the problem.

              Comment


              • #8
                OK. Thanks Nick.

                I hope to get answers from the participants!

                Comment


                • #9
                  I also want to indicate that I tried ‘ttail’ function instead if normal and that did not work.
                  Couls it be that Stata can not identify the state when running the test and hence produce no results?

                  Comment


                  • #10
                    I don't use -mswitch- either but I have some comments.
                    • your data example is likely incomplete because I don't see time or identifiers included
                    • at the bottom of the help for -mswitch- you will see all of the returned locals, scalars, macros that are returned from the command. -r(chi2)- is not among them, so you'll need to check that this code is correct first (or was it ChatGPT?)
                    • supposing you do get a chi2 statistic, a t-based inference wouldn't be appropriate.

                    Comment


                    • #11
                      Leonardo Guizzetti, Thanks! However, the code comes from Stata support and not ChatGPT as the latter always gives incorrect Stata codes. Please see the link FYI https://www.stata.com/support/faqs/s...-coefficients/
                      As you see my code is close to the one in the official Stata website. But, I am still not able to perform the test in this case.

                      I look forward to getting more help.

                      Comment


                      • #12
                        Thanks, everyone!
                        I have now created a new post that might be useful as this one seems not to be successful in grabbing the attention of the users who used -mswitch-

                        here is the new post and I very much look forward to your further contribution https://www.statalist.org/forums/for...witching-model

                        Comment


                        • #13
                          Originally posted by Mike Kraft View Post
                          Leonardo Guizzetti, Thanks! However, the code comes from Stata support and not ChatGPT as the latter always gives incorrect Stata codes. Please see the link FYI https://www.stata.com/support/faqs/s...-coefficients/
                          As you see my code is close to the one in the official Stata website. But, I am still not able to perform the test in this case.

                          I look forward to getting more help.
                          You have not addressed the substantive points in my post, so I will bow out now.

                          First, the FAQ you cite is related to large-sample Wald-type tests. In that specific example, it uses -regress- which is a different command to -mswitch-. You cannot blindly copy code written for one command and expect it to work with another command. Your code appears to be missing a -test- statement (or equivalent) so you should investigate whether that's appropriate.

                          Second, -mswitch- requires -tsset- data, and your data example lack a time variable and any necessary identifier variables.

                          Comment


                          • #14
                            the p-value for a two-tail test is twice the one-tail value. pull of the p-value from r(table) and divide by 2?

                            Comment


                            • #15
                              George Ford Thanks. The results I am going to show now for the p value are indeed equal to the p value divided by 2. But, is this correct in my setting?

                              Leonardo Guizzetti Thanks. I have added the date variable. Data are tsset and is a time series.
                              You spotted an important issue which is the missing test command. I have now incorporated it into the code and got results. As you mentioned, the code should not be taken blindly, so do you have any conceptual objections now to the way it is done? I mean, is it correct to do it this way?



                              The last thing, the p-value shows that the coefficient on infl in State 1 is (marginally) statistically positive. Can I now obtain a one-tailed z or t stats (instead of p value) from the test?



                              Code:
                              mswitch dr gdp, switch(inf) states(2) varswitch vce(oim)
                              
                              test _b[State1:inf]==0
                              
                              local sign_inf1 = sign(_b[State1:inf])
                              
                              display "H_0: coef<=0  p-value = " 1-normal(`sign_inf1'*sqrt(r(chi2)))
                              
                              display "H_0: coef>=0  p-value = " normal(`sign_inf1'*sqrt(r(chi2)))

                              * Relevant results:

                              Code:
                              ------------------------------------------------------------------------------
                                       gdp |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                              -------------+----------------------------------------------------------------
                              State1       |
                                       inf |     .07192   .0559208     1.29   0.198    -.0376827    .1815227
                                     _cons |  -.0018488   .0207744    -0.09   0.929    -.0425658    .0388682
                              -------------+----------------------------------------------------------------
                              State2       |
                                       inf |  -.0975228   .0402512    -2.42   0.015    -.1764136   -.0186319
                                     _cons |     .05434   .0075199     7.23   0.000     .0396012    .0690789
                              -------------+----------------------------------------------------------------
                              ------------------------------------------------------------------------------
                              
                              .  test _b[State1:inf]==0
                              
                               ( 1)  [State1]inf = 0
                              
                                         chi2(  1) =    1.65
                                       Prob > chi2 =    0.1984
                              
                              . local sign_inf1 = sign(_b[State1:inf])
                              
                              .
                              . display "H_0: coef<=0  p-value = " 1-normal(`sign_inf1'*sqrt(r(chi2)))
                              H_0: coef<=0  p-value = .09920307
                              
                              .
                              . display "H_0: coef>=0  p-value = " normal(`sign_inf1'*sqrt(r(chi2)))
                              H_0: coef>=0  p-value = .90079693
                              Code:
                              * Example generated by -dataex-. To install: ssc install dataex
                              clear
                              input float(gdp inf fqdate)
                              .007700333    .5187629 200
                              -.02740002      .34353 201
                               .13628435    .2376328 202
                               .12833123   .19194767 203
                               .02376178    .1695175 204
                              -.10218496   .13180599 205
                              .032250106   .14218333 206
                               .10955863  .030188626 207
                              -.03913185  .034655128 208
                              .072813794   .00974617 209
                              .015213448  -.05903455 210
                                .0759132  -.09023324 211
                               .08372551   .02818246 212
                               .01988073   .05389125 213
                               .11137556     .086043 214
                               .04189473   .22799003 215
                               .03005812  .008939946 216
                               .04916773   .04671769 217
                               .02101729    .1232737 218
                               .02772906  -.12611626 219
                              .011852331 -.069527514 220
                              -.06285229   -.1504436 221
                               .05395768   -.1771323 222
                              -.08499915   -.1628624 223
                               .10538375  -.07289606 224
                               .04541152 -.003922231 225
                               .03296767   .07905588 226
                               .07891027    .1704167 227
                               .01647786    .2209274 228
                              .033901338   .11310016 229
                               .07701728    .0816167 230
                               .02512829    .2321612 231
                              .008445978   .17182833 232
                              end
                              format %tq fqdate
                              Last edited by Mike Kraft; 22 Aug 2023, 21:24.

                              Comment

                              Working...
                              X