Announcement

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

  • How to use -tuples- to do model selection?@Nick Cox

    Dear all,
    I want to use -tuples- to do model selection.My code is here,
    Code:
    webuse grunfeld,clear
    global m "mvalue kstock L.mvalue  c.mvalue#c.mvalue c.kstock#c.kstock c.mvalue#c.kstock L.kstock"
    tuples $m i.year,cond(1&2&8 !(4&!1)  !(5&!2)  !(6&(!(1&2)))) min(5)
    forval i=1/`ntuples'{
        xtreg invest `tuple`i'',fe r
    }
    I want to select the models in which p-values of mvalve and kstock are smaller than 0.1(statisc significant) ,
    and both the coefficients of mvalue and kstock are positive .Then print the selected results on the screen.Maybe print like

    model beta beta_se p-value
    1 0.4521 0.0234 0.000***
    3
    6
    12
    ...

    Anyone can give some suggestions?Many thanks in advance.



    Best regards.
    Raymond
    Best regards.

    Raymond Zhang
    Stata 17.0,MP

  • #2
    the result can also print like, model beta_mvaluve p_mvalue beta_kstock p_kstock 1 … 8 … 16 … 23 … …
    Best regards.

    Raymond Zhang
    Stata 17.0,MP

    Comment


    • #3
      Because of the interactions, I think it makes the most sense to use margins. You can add your restrictions at the end

      Code:
      webuse grunfeld,clear
      local models "mvalue kstock L.mvalue  c.mvalue#c.mvalue c.kstock#c.kstock c.mvalue#c.kstock L.kstock"
      tuples `models' i.year,cond(1&2&8 !(4&!1)  !(5&!2)  !(6&(!(1&2)))) min(5)
      
      local x = 1
      forval i=1/`ntuples'{
          
          quietly {
              xtreg invest `tuple`i'',fe r
      
              local model = "`e(cmdline)'"
              margins, dydx(mvalue kstock)    saving(M`x', replace)
              preserve 
              use "M`x'", clear 
              gen model = "`model'"
              save "M`x'", replace 
              restore 
              local ++x
          }
      }
      clear 
      forvalues f = 1/`=`x'-1' {
          append using M`f'.dta
          erase "M`f'.dta"
      }
      order model
      And from here you can add if qualifiers to list.

      Code:
       list model _deriv _pvalue , noobs divider
      
        +------------------------------------------------------------------------------------------------------------------------------------+
        | model                                                                                                          | _deriv |  _pvalue |
        |----------------------------------------------------------------------------------------------------------------+--------+----------|
        | xtreg invest mvalue kstock c.mvalue#c.kstock L.kstock i.year,fe r                                              | mvalue | 8.71e-10 |
        | xtreg invest mvalue kstock c.mvalue#c.kstock L.kstock i.year,fe r                                              | kstock | .5801986 |
        | xtreg invest mvalue kstock c.kstock#c.kstock L.kstock i.year,fe r                                              | mvalue | 4.26e-11 |
        | xtreg invest mvalue kstock c.kstock#c.kstock L.kstock i.year,fe r                                              | kstock | .7551234 |
        | xtreg invest mvalue kstock c.kstock#c.kstock c.mvalue#c.kstock i.year,fe r                                     | mvalue | 1.96e-07 |
        |----------------------------------------------------------------------------------------------------------------+--------+----------|
        | xtreg invest mvalue kstock c.kstock#c.kstock c.mvalue#c.kstock i.year,fe r                                     | kstock |  .857313 |
        | xtreg invest mvalue kstock c.mvalue#c.mvalue L.kstock i.year,fe r                                              | mvalue | .0129901 |
        | xtreg invest mvalue kstock c.mvalue#c.mvalue L.kstock i.year,fe r                                              | kstock | .0008966 |
        | xtreg invest mvalue kstock c.mvalue#c.mvalue c.mvalue#c.kstock i.year,fe r                                     | mvalue | .0539711 |
        | xtreg invest mvalue kstock c.mvalue#c.mvalue c.mvalue#c.kstock i.year,fe r                                     | kstock | .9955118 |
        |----------------------------------------------------------------------------------------------------------------+--------+----------|
        | xtreg invest mvalue kstock c.mvalue#c.mvalue c.kstock#c.kstock i.year,fe r                                     | mvalue | .0395627 |
        | xtreg invest mvalue kstock c.mvalue#c.mvalue c.kstock#c.kstock i.year,fe r                                     | kstock | .0595046 |
        | xtreg invest mvalue kstock L.mvalue L.kstock i.year,fe r                                                       | mvalue | .0000962 |
        | xtreg invest mvalue kstock L.mvalue L.kstock i.year,fe r                                                       | kstock | .0003293 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.kstock i.year,fe r                                              | mvalue | .0000118 |
        |----------------------------------------------------------------------------------------------------------------+--------+----------|
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.kstock i.year,fe r                                              | kstock |   .92354 |
        | xtreg invest mvalue kstock L.mvalue c.kstock#c.kstock i.year,fe r                                              | mvalue | 9.50e-06 |
        | xtreg invest mvalue kstock L.mvalue c.kstock#c.kstock i.year,fe r                                              | kstock | .1607613 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue i.year,fe r                                              | mvalue | .0179141 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue i.year,fe r                                              | kstock | 2.26e-08 |
        |----------------------------------------------------------------------------------------------------------------+--------+----------|
        | xtreg invest mvalue kstock c.kstock#c.kstock c.mvalue#c.kstock L.kstock i.year,fe r                            | mvalue | 4.51e-08 |
        | xtreg invest mvalue kstock c.kstock#c.kstock c.mvalue#c.kstock L.kstock i.year,fe r                            | kstock | .4762664 |
        | xtreg invest mvalue kstock c.mvalue#c.mvalue c.mvalue#c.kstock L.kstock i.year,fe r                            | mvalue | .0381245 |
        | xtreg invest mvalue kstock c.mvalue#c.mvalue c.mvalue#c.kstock L.kstock i.year,fe r                            | kstock | .6003485 |
        | xtreg invest mvalue kstock c.mvalue#c.mvalue c.kstock#c.kstock L.kstock i.year,fe r                            | mvalue | .0178053 |
        |----------------------------------------------------------------------------------------------------------------+--------+----------|
        | xtreg invest mvalue kstock c.mvalue#c.mvalue c.kstock#c.kstock L.kstock i.year,fe r                            | kstock | .7118102 |
        | xtreg invest mvalue kstock c.mvalue#c.mvalue c.kstock#c.kstock c.mvalue#c.kstock i.year,fe r                   | mvalue | .0531672 |
        | xtreg invest mvalue kstock c.mvalue#c.mvalue c.kstock#c.kstock c.mvalue#c.kstock i.year,fe r                   | kstock | .8725814 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.kstock L.kstock i.year,fe r                                     | mvalue | .0023003 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.kstock L.kstock i.year,fe r                                     | kstock | .6138697 |
        |----------------------------------------------------------------------------------------------------------------+--------+----------|
        | xtreg invest mvalue kstock L.mvalue c.kstock#c.kstock L.kstock i.year,fe r                                     | mvalue |  .008351 |
        | xtreg invest mvalue kstock L.mvalue c.kstock#c.kstock L.kstock i.year,fe r                                     | kstock | .8538894 |
        | xtreg invest mvalue kstock L.mvalue c.kstock#c.kstock c.mvalue#c.kstock i.year,fe r                            | mvalue | 7.00e-06 |
        | xtreg invest mvalue kstock L.mvalue c.kstock#c.kstock c.mvalue#c.kstock i.year,fe r                            | kstock |  .788289 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue L.kstock i.year,fe r                                     | mvalue | .0387527 |
        |----------------------------------------------------------------------------------------------------------------+--------+----------|
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue L.kstock i.year,fe r                                     | kstock | .0025326 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue c.mvalue#c.kstock i.year,fe r                            | mvalue | .0376394 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue c.mvalue#c.kstock i.year,fe r                            | kstock | .9730026 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue c.kstock#c.kstock i.year,fe r                            | mvalue | .0280921 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue c.kstock#c.kstock i.year,fe r                            | kstock | .1295566 |
        |----------------------------------------------------------------------------------------------------------------+--------+----------|
        | xtreg invest mvalue kstock c.mvalue#c.mvalue c.kstock#c.kstock c.mvalue#c.kstock L.kstock i.year,fe r          | mvalue | .0391878 |
        | xtreg invest mvalue kstock c.mvalue#c.mvalue c.kstock#c.kstock c.mvalue#c.kstock L.kstock i.year,fe r          | kstock | .4920634 |
        | xtreg invest mvalue kstock L.mvalue c.kstock#c.kstock c.mvalue#c.kstock L.kstock i.year,fe r                   | mvalue | .0049024 |
        | xtreg invest mvalue kstock L.mvalue c.kstock#c.kstock c.mvalue#c.kstock L.kstock i.year,fe r                   | kstock | .4963436 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue c.mvalue#c.kstock L.kstock i.year,fe r                   | mvalue | .0620928 |
        |----------------------------------------------------------------------------------------------------------------+--------+----------|
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue c.mvalue#c.kstock L.kstock i.year,fe r                   | kstock | .6404609 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue c.kstock#c.kstock L.kstock i.year,fe r                   | mvalue | .0616416 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue c.kstock#c.kstock L.kstock i.year,fe r                   | kstock |  .800316 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue c.kstock#c.kstock c.mvalue#c.kstock i.year,fe r          | mvalue |   .03653 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue c.kstock#c.kstock c.mvalue#c.kstock i.year,fe r          | kstock | .8325533 |
        |----------------------------------------------------------------------------------------------------------------+--------+----------|
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue c.kstock#c.kstock c.mvalue#c.kstock L.kstock i.year,fe r | mvalue | .0682878 |
        | xtreg invest mvalue kstock L.mvalue c.mvalue#c.mvalue c.kstock#c.kstock c.mvalue#c.kstock L.kstock i.year,fe r | kstock | .5149577 |
        +------------------------------------------------------------------------------------------------------------------------------------+

      Comment


      • #4
        Justin Blasongame thank you for your kind help. Raymond
        Best regards.

        Raymond Zhang
        Stata 17.0,MP

        Comment

        Working...
        X