Announcement

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

  • -mi test- and specification of factor variable coefficients

    help mi_test suggests that the specification of plain vanilla tests after mi estimate are of the form mi test coeflist .How does one specify coeflist in the case of factor variables? I can't get this to work (see below) for the case of a single factor variable, let alone interaction terms for 2 factor variables.

    I can't find advice on this in the help or manuals (but may have missing something). I can get results if I specify the coeflist manually, but I want to avoid that.

    Code:
     . mi estimate: reg gini_net  i.year if region == 5 & year > 1990 & year < 2007
      
    Multiple-imputation estimates                     Imputations     =        100
    Linear regression                                 Number of obs   =        401
                                                      Average RVI     =     0.0468
                                                      Largest FMI     =     0.0604
                                                      Complete DF     =        385
    DF adjustment:   Small sample                     DF:     min     =     355.39
                                                              avg     =     363.17
                                                              max     =     378.04
    Model F test:       Equal FMI                     F(  15,  382.8) =       0.53
    Within VCE type:          OLS                     Prob > F        =     0.9249
      
    ------------------------------------------------------------------------------
        gini_net |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
            year |
           1992  |   .2601348   1.525127     0.17   0.865    -2.738659    3.258929
           1993  |   1.006815     1.5231     0.66   0.509    -1.988172    4.001803
           1994  |   1.377235   1.527145     0.90   0.368    -1.625771     4.38024
           1995  |   1.623852   1.514133     1.07   0.284    -1.353781    4.601486
           1996  |   1.672173   1.519782     1.10   0.272    -1.316452    4.660798
           1997  |   1.816323   1.521787     1.19   0.233    -1.176278    4.808924
           1998  |   2.290752   1.540125     1.49   0.138    -.7379953    5.319499
           1999  |    1.96233   1.520791     1.29   0.198    -1.028517    4.953178
           2000  |   2.744941    1.56078     1.76   0.079    -.3245387     5.81442
           2001  |   2.897571   1.561122     1.86   0.064    -.1725886    5.967731
           2002  |   1.074202   1.546792     0.69   0.488    -1.967778    4.116182
           2003  |   2.202671   1.569541     1.40   0.161    -.8839185     5.28926
           2004  |   1.501412   1.560643     0.96   0.337    -1.567526    4.570351
           2005  |   1.584315   1.597405     0.99   0.322    -1.556956    4.725586
           2006  |    2.01109   1.657117     1.21   0.226    -1.247545    5.269725
                 |
           _cons |   44.85401   1.128164    39.76   0.000     42.63529    47.07273
    ------------------------------------------------------------------------------
      
    .
    end of do-file
      . mi test i.(1991/2006)year
    note: assuming equal fractions of missing information
    i:  operator invalid
    r(198);
      
    . mi test 1991.year 1992.year 1993.year 1994.year 1995.year 1996.year 1997.year 1998.year 1999.year 2000.year 2001.year 2002.year 2003.year 2004.year 2005.year 2006.year
    note: assuming equal fractions of missing information
       ( 1)  1991b.year = 0
     ( 2)  1992.year = 0
     ( 3)  1993.year = 0
     ( 4)  1994.year = 0
     ( 5)  1995.year = 0
     ( 6)  1996.year = 0
     ( 7)  1997.year = 0
     ( 8)  1998.year = 0
     ( 9)  1999.year = 0
     (10)  2000.year = 0
     (11)  2001.year = 0
     (12)  2002.year = 0
     (13)  2003.year = 0
     (14)  2004.year = 0
     (15)  2005.year = 0
     (16)  2006.year = 0
           Constraint 1 dropped
             F( 15, 382.8) =    0.53
                Prob > F =    0.9249
    .






  • #2
    Stephen, I did not try this, but it seems you have a typo in

    Code:
    mi test i.(1991/2006)year
    The dot has to be after the parentheses as in

    Code:
    mi test i(1991/2006).year
    Best
    Daniel

    Comment


    • #3
      Thanks for looking into this, Daniel. Unfortunately, your suggestion leads to an error as well:

      Code:
      . mi test i(1991/2006).year
      note: assuming equal fractions of missing information
      i not found
      r(111);
      If I can beat this one, I guess we'll be able to beat the problem of dealing with interacted factor variables as well.

      Comment


      • #4
        I'm not sure it will work, but what if you leave the i out of the expression?

        Code:
        mi test (1991/2006).year
        What made me think of this is that when you specify the test year by year, you don't include the i prefix before the years. As I said, not sure it will work but I figure it's worth a try.
        Alfonso Sanchez-Penalver

        Comment


        • #5
          First off, none of these suggestions actually work for the plain test:

          Code:
          sysuse auto, clear
          reg mpg i.rep78 foreign if _m==0
          test rep78
          test i.rep78
          test i(2/5).rep78
          test (2/5).rep78
          That is, not until you use the testparm form (which is not supported by mi)

          Code:
          testparm i(2/5).rep78
          testparm i.rep78
          To turn this around and develop a working solution specifically in terms of test, avoiding cumbersome typing, consider

          Code:
          levelsof rep78 if e(sample), local(theselevels)
          local rep78levels = subinstr("`theselevels' "," ",".rep78 ", .)
          test `rep78levels'
          Note there is a space after `theselevels' in the string manipulation command. It is needed to correctly append .rep78 to the last level encountered. Note also that the whole thing is fragile and subject to the limits of Stata on the length of strings and string expressions. With this in hand, we can try this on mi, as well:

          Code:
          mi set wide
          mi register imputed rep78
          mi register regular mpg foreign length
          mi impute pmm rep78 = mpg foreign length, add(10)
          mi estimate : reg mpg i.rep78 foreign
          mi test `rep78levels'
          -- Stas Kolenikov || http://stas.kolenikov.name
          -- Principal Survey Scientist, Abt SRBI
          -- Opinions stated in this post are mine only

          Comment


          • #6
            As a canned work-around you may also use fvexpand, as in

            Code:
            sysuse auto
            fvexpand i.rep78
            ret li
            Probably you want to exclude the base level.

            However, I would like to see the a mi testparm command in the future, which I imagine should not be too hard to implement. You may write your own wrapper.

            Best
            Daniel

            Comment


            • #7
              As Stas pointed out, test and mi test do not support the varlist specification that Stephen desires but rather the coeflist specification; you can read more about the definition of coeflist in the help file for the test command. The varlist specification is supported only by testparm. We will consider adding an mi testparm command in the future.

              Meanwhile, Stephen can use the _ms_extract_varlist command to convert the factor-variable specification into a list of "factor coefficients" as stored in e(b), and use that list with mi test or test. This is how testparm is handling the varlist specification. For multiple-equations commands, you may also use the equation() option to choose the appropriate equation; type help _ms_extract_varlist for details.

              Below, I show several examples for test but they can be applied directly to mi test.

              Code:
              . sysuse auto, clear
              . regress mpg weight i.rep78
              <output omitted>
              
              . _ms_extract_varlist i.rep78, noomitted
              . test `r(varlist)'
              
               ( 1)  2.rep78 = 0
               ( 2)  3.rep78 = 0
               ( 3)  4.rep78 = 0
               ( 4)  5.rep78 = 0
              
                     F(  4,    63) =    1.10
                          Prob > F =    0.3668
              
              . testparm i.rep78
              
               ( 1)  2.rep78 = 0
               ( 2)  3.rep78 = 0
               ( 3)  4.rep78 = 0
               ( 4)  5.rep78 = 0
              
                     F(  4,    63) =    1.10
                          Prob > F =    0.3668

              We can refer to a range of levels of a factor variable.

              Code:
              . _ms_extract_varlist i(2/4).rep78, noomitted
              . test `r(varlist)'
              
               ( 1)  2.rep78 = 0
               ( 2)  3.rep78 = 0
               ( 3)  4.rep78 = 0
              
                     F(  3,    63) =    0.02
                          Prob > F =    0.9964
              
              . testparm i(2/4).rep78
              
               ( 1)  2.rep78 = 0
               ( 2)  3.rep78 = 0
               ( 3)  4.rep78 = 0
              
                     F(  3,    63) =    0.02
                          Prob > F =    0.9964

              We can perform estimation using a subsample and automatically obtain the levels of the factor variable relevant to that subsample.

              Code:
              . regress mpg weight i.rep78 if foreign==1
              <output omitted>
              
              . _ms_extract_varlist i.rep78, noomitted
              . test `r(varlist)'
              
               ( 1)  4.rep78 = 0
               ( 2)  5.rep78 = 0
              
                     F(  2,    17) =    4.00
                          Prob > F =    0.0378
              
              . testparm i.rep78
              
               ( 1)  4.rep78 = 0
               ( 2)  5.rep78 = 0
              
                     F(  2,    17) =    4.00
                          Prob > F =    0.0378

              Comment


              • #8
                Thank you for all the comments. And Yulia: thanks too for being very diplomatic about my lack of the appreciation of the distinction between the varlist specification and the coeflist specification -- and of course for the info about _ms_extract_varlist.

                Comment

                Working...
                X