Announcement

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

  • Estimates store with linear combinations of parameters

    Hello,

    I have data which resembles the following:


    clear
    input double(y x1 x2)
    12 3 5
    3 2 4
    1 3 3
    2 1 1
    3 3 2
    3 2 3
    1 4 2
    end
    [/CODE]

    Here, I have a dependent variable (y), and two independent variables, x1 and x2. Essentially, I wish to run two separate regressions, one of y on x1 and the other of y on x2. The first regression:

    Code:
    regress y x1
    results in coefficient estimates of the intercept and the slope coefficient x1, which is stored as a scalar, retrievable in _b[x1]. The same idea holds for x2, where the coefficient is in _b[x2].

    I wish to store these coefficients after the regressions, and produce a table, which as two rows, and two columns column. The first corresponds to the proportion of _b[x1] in the sum of _b[x1] and _b[x2].. The second row corresponds to the proportion of _b[x2] in the sum of _b[x1] and _b[x2]. The second row, should contain the standard errors of these proportionate quantities. The table, ideally, should look like this:


    Code:
    Proportion                                   Standard error
    
    _b[x1]/(_b[x1] +_b[x2])          SE(_b[x1]/(_b[x1] +_b[x2]) 
    _b[x2]/(_b[x1] +_b[x2])          SE(_b[x2]/(_b[x1] +_b[x2])

    I am certain the -est sto- command is applicable here, but I could definitely benefit from some guidance at this point.


    Kind regards,
    CS.

  • #2
    To the extent that these proportions are sensible to compute, this shows one approach.

    Code:
    reg y x1
    est sto M1
    reg y x2
    est sto M2
    suest M1 M2
    nlcom (Pr1: [M1_mean]_b[x1] / ([M1_mean]_b[x1] + [M2_mean]_b[x2]) ) (Pr2: [M2_mean]_b[x2] / ([M1_mean]_b[x1] + [M2_mean]_b[x2]) ), post
    mat list r(table)
    Selected results

    Code:
    . suest M1 M2
    
    Simultaneous results for M1, M2                              Number of obs = 7
    
    ------------------------------------------------------------------------------
                 |               Robust
                 | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    M1_mean      |
              x1 |         .3   1.126893     0.27   0.790    -1.908669    2.508669
           _cons |        2.8    1.98199     1.41   0.158    -1.084629    6.684629
    -------------+----------------------------------------------------------------
    M1_lnvar     |
           _cons |   2.858766   .5574222     5.13   0.000     1.766239    3.951294
    -------------+----------------------------------------------------------------
    M2_mean      |
              x2 |   2.078947   1.012836     2.05   0.040      .093825     4.06407
           _cons |  -2.368421   2.530771    -0.94   0.349    -7.328641    2.591798
    -------------+----------------------------------------------------------------
    M2_lnvar     |
           _cons |   2.098986   .2827189     7.42   0.000     1.544867    2.653105
    ------------------------------------------------------------------------------
    r; t=0.02 15:29:06
    
    .
    . nlcom (Pr1: [M1_mean]_b[x1] / ([M1_mean]_b[x1] + [M2_mean]_b[x2]) ) (Pr2: [M2_mean]_b[x2] / ([M1_mean]_b[x1] + [M2_mean]_b[x2]) ), post
    
             Pr1: [M1_mean]_b[x1] / ([M1_mean]_b[x1] + [M2_mean]_b[x2])
             Pr2: [M2_mean]_b[x2] / ([M1_mean]_b[x1] + [M2_mean]_b[x2])
    
    ------------------------------------------------------------------------------
                 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             Pr1 |   .1261062   .3994712     0.32   0.752     -.656843    .9090554
             Pr2 |   .8738938   .3994712     2.19   0.029     .0909446    1.656843
    ------------------------------------------------------------------------------
    From here, the estimates will then be stored in e(b) and variances along the diagonals of the e(V) matrix. More easily, the -r(table)- matrix is more straightforward.

    Comment


    • #3
      Leonardo Guizzetti Thank you very much. Just what I was looking for . One final point: how I can transfer the results stored in r(table) into say a word document?

      Comment


      • #4
        You’re welcome. There are many ways to do this. I would look at -putdocx- as most straightforward, but there is also -collect- as official commands, then many user-contributed commands beyond.

        Comment


        • #5
          Thank you so much. Much appreciated

          Comment

          Working...
          X