Announcement

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

  • MC Simulation: How to return regression results for multiple regressions?

    Hello,

    I am attempting to return coefficient results from multiple regressions using a simulation. Below is an example of a basic code. Note the simulation will only return results from the last regression ran and not the first. How can I return results from both regressions?

    Important Note: This is simple to do with return scalar method for each coefficient (ie return scalar beta1 = _b[x1]), but I interested in some kind of command because I am going to have the number of regressors be variable. For example, I want the user to simply be able to say, I want ten regressors, and my simulation spits out 10 coefficient estimates for 2 regressions for 100 simulations. This is all without having the user to type the return function 10 times in the lines after each regression command line, and then also having to type beta1=r(beta1) for 20 different betas in the simiulation command line.

    I have been stuck on this for a while so please be very clear with any response. Thank you!



    clear

    program drop beta
    program beta, rclass

    clear
    set obs 100
    gen x1 = rnormal(0,3)
    gen x2 = rnormal(0,4)
    gen x3 = rnormal(0,4)
    gen y= rnormal(0,1)
    reg y x1 x2

    gen new_y = rnormal(0,3)
    reg new_y x1 x3

    end

    simulate _b, reps(100): beta




  • #2
    Whenever you run an estimation command in Stata, all results of previous estimation commands in e(), _b, and _se are wiped out. So the second regression obliterates the results of the first. What you need to do is store the results you want from the first regression (in this case by returning them as scalars from program beta) before going on to the second one.

    Code:
    clear
    
    capture program drop beta
    program beta, rclass
    
    clear
    set obs 100
    gen x1 = rnormal(0,3)
    gen x2 = rnormal(0,4)
    gen x3 = rnormal(0,4)
    gen y= rnormal(0,1)
    reg y x1 x2
    return scalar b11 = _b[x1]
    return scalar b12 = _b[x2]
    
    gen new_y = rnormal(0,3)
    reg new_y x1 x3
    return scalar b21 = _b[x1]
    return scalar b23 = _b[x3]
    
    end
    
    simulate reg1_bx1 = r(b11) reg1_bx2 = r(b12) reg2_bx1 = r(b21) reg2_bx3 = r(b23), ///
        reps(100): beta
    Added: It is the culture in this community that we use our real given and surnames as our username, to promote collegiality and professionalism. The Forum software does not allow you to edit the username in your profile, but you can click on Contact Us in the lower right corner of this page and message the Forum administrator requesting that he make the change for you. Thank you for doing so at your earliest convenience.
    Last edited by Clyde Schechter; 05 Dec 2018, 09:28.

    Comment


    • #3
      To my knowledge referring to matrices is not possible in Stata simulations, because -simulate- can work only with scalars.

      So you need to work out a solution from what Clyde suggested, you need to work out somehow your solution in terms of scalars.



      Comment

      Working...
      X