Announcement

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

  • Generate Variable from Beta Coefficient

    Hello,
    After running a simple linear regression with just one independent variable, I request to have the beta coefficient reported.
    This is fine and in this case comes back as beta .1651711
    Is is possible to generate a variable where all observations will have this beta.
    I have tried gen beta1=_b[OR_to_ORLTO_nmfp] - which is the independent variable in question. Whilst the beta1 var does generate, it does not report back the same beta as above.
    Thanks

  • #2
    By "beta", do you mean a standardized coefficient reported by regress when adding the -beta- option? If so, Stata stores the raw coefficient. You can, however, pick this from the matrix -e(beta)-.

    Code:
    sysuse auto, clear
    regress mpg weight disp, beta
    mat l e(beta)
    gen double wanted= e(beta)[1, "weight"]
    sum wanted
    Res.:

    Code:
    . regress mpg weight disp, beta
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(2, 71)        =     66.79
           Model |  1595.40969         2  797.704846   Prob > F        =    0.0000
        Residual |  848.049768        71  11.9443629   R-squared       =    0.6529
    -------------+----------------------------------   Adj R-squared   =    0.6432
           Total |  2443.45946        73  33.4720474   Root MSE        =    3.4561
    
    ------------------------------------------------------------------------------
             mpg | Coefficient  Std. err.      t    P>|t|                     Beta
    -------------+----------------------------------------------------------------
          weight |  -.0065671   .0011662    -5.63   0.000                -.8821898
    displacement |   .0052808   .0098696     0.54   0.594                 .0838253
           _cons |   40.08452    2.02011    19.84   0.000                        .
    ------------------------------------------------------------------------------
    
    . 
    . mat l e(beta)
    
    e(beta)[1,2]
              weight  displacement
    r1    -.88218979     .08382533
    
    . 
    . gen double wanted= e(beta)[1, "weight"]
    
    . 
    . sum wanted
    
        Variable |        Obs        Mean    Std. dev.       Min        Max
    -------------+---------------------------------------------------------
          wanted |         74   -.8821898           0  -.8821898  -.8821898

    Comment


    • #3
      Thanks Andrew.
      I'm getting 'matrix e(beta) not found' error when it reaches that line of the code

      Comment


      • #4
        works for me in v18.

        did the model actually estimate?

        maybe e(b) in older versions?
        Last edited by George Ford; 23 Jan 2024, 09:21.

        Comment


        • #5
          Refer to FAQ Advice #11:

          11. What should I say about the version of Stata I use?

          The current version of Stata is 18. Please specify if you are using an earlier version; otherwise, the answer to your question may refer to commands or features unavailable to you. Moreover, as bug fixes and new features are issued frequently by StataCorp, make sure that you update your Stata before posting a query, as your problem may already have been solved.
          For workarounds in earlier versions of Stata, see https://www.statalist.org/forums/for...s-for-coefplot or even https://www.statalist.org/forums/for...a-coefficients.

          Comment


          • #6
            I'm using Stata 17/ MP

            Comment


            • #7
              Thanks got it now....installed esttab

              Comment

              Working...
              X