Announcement

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

  • Displaying ivqregress results

    Dear All,
    I'm trying to display ivqregress results by using the suite of commands -collect-. My outcome variable is categorized BMI then I have three equations in the model: Overweight, Obesity and Pathologic Obesity. These models have been fitted to four surveys and I want to display results with equations in the rows and surveys in the columns. I'm using the following code:

    collect create iv_bmi, replace

    collect _r_b _r_ci, tag(model[(ENFR2005)]): ivqregress smooth imc (i.ni_cat2inv = i.ingresocat) i.age_cat5 i.sexo i.hta i.dbt if enfr==2005, quantile(52 84 95)

    collect _r_b _r_ci, tag(model[(ENFR2009)]): ivqregress smooth imc (i.ni_cat2inv = i.ingresocat) i.age_cat5 i.sexo i.hta i.dbt if enfr==2009, quantile(47 82 93)

    collect dims

    collect layout (coleq#colname) (results _r_b _r_ci)

    and the table looks like this:
    Coefficient 95% CI
    q52
    Primary/High School 0.00
    Graduated 1.90 1.35 2.45
    0.00
    30-39 2.00 1.84 2.16
    40-49 3.05 2.87 3.23
    50-59 3.53 3.33 3.73
    60 or > 2.93 2.71 3.14
    Male 0.00
    Female -2.13 -2.24 -2.02
    No 0.00
    Yes 1.56 1.38 1.74
    No 0.00
    Yes 1.19 0.97 1.40
    Intercept 23.18 22.97 23.38
    q84
    Primary/High School 0.00
    Graduated 0.28 -0.69 1.25
    0.00
    30-39 2.42 2.17 2.68
    40-49 3.75 3.45 4.04
    50-59 3.67 3.32 4.02
    60 or > 2.43 2.08 2.77
    Male 0.00
    Female -0.99 -1.18 -0.80
    No 0.00
    Yes 2.18 1.89 2.48
    No 0.00
    Yes 1.96 1.57 2.35
    Intercept 27.41 27.06 27.77
    q95
    Primary/High School 0.00
    Graduated -3.75 -5.32 -2.17
    0.00
    30-39 2.31 1.73 2.88
    40-49 3.09 2.47 3.72
    50-59 2.79 2.03 3.55
    60 or > 0.78 0.07 1.48
    Male 0.00
    Female 0.15 -0.30 0.60
    No 0.00
    Yes 2.65 1.97 3.33
    No 0.00
    Yes 2.99 2.11 3.86
    Intercept 33.25 32.22 34.29
    q47
    Primary/High School 0.00
    Graduated 1.74 0.80 2.67
    0.00
    30-39 1.30 1.06 1.53
    40-49 1.54 1.30 1.78
    50-59 1.73 1.47 1.99
    60 or > 1.55 1.28 1.83
    Male 0.00
    Female -2.15 -2.28 -2.02
    No 0.00
    Yes 2.02 1.86 2.19
    No 0.00
    Yes 1.46 1.21 1.71
    Intercept 23.62 23.22 24.02
    q82
    Primary/High School 0.00
    Graduated 0.06 -1.96 2.08
    0.00
    30-39 1.70 1.34 2.07
    40-49 2.01 1.62 2.40
    50-59 2.06 1.65 2.48
    60 or > 1.36 0.92 1.81
    Male 0.00
    Female -0.81 -1.00 -0.61
    No 0.00
    Yes 2.48 2.23 2.74
    No 0.00
    Yes 2.14 1.81 2.47
    Intercept 27.88 27.12 28.63
    q93
    Primary/High School 0.00
    Graduated -1.89 -3.77 -0.00
    0.00
    30-39 1.55 0.83 2.28
    40-49 2.19 1.48 2.91
    50-59 2.17 1.42 2.92
    60 or > 0.93 0.16 1.69
    Male 0.00
    Female -0.02 -0.37 0.33
    No 0.00
    Yes 2.63 2.21 3.04
    No 0.00
    Yes 2.51 1.79 3.22
    Intercept 31.67 30.58 32.75
    With the code the results are displayed one model after the other and I want one by side the other.
    Can someone help me?
    Thank you in advance

  • #2
    You need to interact the dimensions defining the stored models with the column dimensions. Here is an example (see highlighted):

    Code:
    webuse assets2, clear
    collect clear
    collect _r_b _r_ci, tag(model[(married)]): ivqregress iqr assets (i.p401k = i.e401k) income age familysize i.ira i.pension i.ownhome educ if married
    collect _r_b _r_ci, tag(model[(notmarried)]): ivqregress iqr assets (i.p401k = i.e401k) income age familysize i.ira i.pension i.ownhome educ if !married
    collect dims
    collect layout (colname) (cmdset[1]#(_r_b ) cmdset[2]#(_r_b))
    Res.:

    Code:
    . collect layout (colname) (cmdset[1]#(_r_b ) cmdset[2]#(_r_b))
    
    Collection: default
          Rows: colname
       Columns: cmdset[1]#(_r_b ) cmdset[2]#(_r_b)
       Table 1: 13 x 2
    
    --------------------------------------------
                       |           1           2
                       | Coefficient Coefficient
    -------------------+------------------------
    No                 |           0           0
    Yes                |    6653.299    3582.471
    Household income   |    .1893788    .0827741
    Age                |    188.5805    29.66423
    Household size     |   -295.8322   -102.7572
    No                 |           0           0
    Yes                |    24685.66    18706.49
    No pension         |           0           0
    Receives pension   |   -1399.455    19.17392
    No                 |           0           0
    Yes                |   -232.1314    243.4921
    Years of education |   -182.4329   -14.01141
    Intercept          |   -9527.379   -2142.279
    --------------------------------------------
    Last edited by Andrew Musau; 29 Jun 2026, 12:27.

    Comment


    • #3
      Dear Andrew,
      thank you very much. I've added to my code the following row: collect layout (colname) (cmdset[1]#(_r_b _r_ci) cmdset[2]#(_r_b _r_ci)) and now I've obtain the following messagge:
      . collect layout (colname) (cmdset[1]#(_r_b _r_ci) cmdset[2]#(_r_b _r_ci))

      Collection: iv_bmi
      Rows: colname
      Columns: cmdset[1]#(_r_b _r_ci) cmdset[2]#(_r_b _r_ci)

      Your layout specification does not uniquely match any items. One or more of the following
      dimensions might help uniquely match items: age_cat5, coleq, dbt, hta, model, ni_cat2inv,
      sexo.

      Comment


      • #4
        From #1, you are estimating across quantiles. These are levels within the dimension coleq. The following is not tested:

        Code:
        local quantiles
        collect levelsof coleq
        foreach q in `s(levels)'{
            local quantiles `quantiles' coleq[`q']#(_r_b _r_ci)
        }
        collect layout (colname) (`quantiles')
        If this does not work, please provide a data example using dataex that creates an example of the tables in #1.
        Last edited by Andrew Musau; 30 Jun 2026, 07:59.

        Comment


        • #5
          This example confirms #4 works.

          Code:
          webuse assets2, clear
          collect clear
          collect _r_b _r_ci: ivqregress iqr assets (i.p401k = i.e401k) income age familysize, quantile(52 84 95)
          
          local quantiles
          collect levelsof coleq
          foreach q in `s(levels)'{
              local quantiles `quantiles' coleq[`q']#(_r_b _r_ci)
          }
          collect layout (colname) (`quantiles')
          Res.:

          Code:
          Collection: default
                Rows: colname
             Columns: coleq[q52]#(_r_b _r_ci) coleq[q84]#(_r_b _r_ci)
                      coleq[q95]#(_r_b _r_ci)
             Table 1: 6 x 6
          
          ------------------------------------------------------------------------------------------------------------------
                           |         q52                 q52         q84                 q84         q95                 q95
                           | Coefficient        95% CI       Coefficient        95% CI       Coefficient        95% CI      
          -----------------+------------------------------------------------------------------------------------------------
          No               |           0                               0                               0                    
          Yes              |    5740.978  4507.304  6974.652    9701.633  5756.123  13647.14    3487.239 -5126.108  12100.59
          Household income |    .3174947   .283479  .3515104    .9791422  .9125421  1.045742    2.012705  1.717391  2.308018
          Age              |    224.4077  195.8628  252.9527    905.9105  791.2425  1020.578    1582.251  1287.617  1876.884
          Household size   |   -737.6436 -873.8362 -601.4511   -1763.951 -2140.192 -1387.709   -2574.577 -3239.373  -1909.78
          Intercept        |   -12472.43 -13892.06 -11052.81   -35600.73 -39089.47 -32111.98   -56004.47 -63912.87 -48096.07
          ------------------------------------------------------------------------------------------------------------------
          
          .
          Last edited by Andrew Musau; 30 Jun 2026, 08:19.

          Comment


          • #6
            I've modified the code a bit, and now it works. Thank you

            Comment

            Working...
            X