Announcement

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

  • Quickly Calculate Cumulative Regression Coefficients

    How do I sum two or more regression coefficients, including standard errors? I currently do it 'manually', but I suspect that there is a better way. Below is an example of what I would do to find the cumulative coefficient of female, MW, and the interaction. Ideally, a solution would be able to accommodate n>1.


    Untitled.png

    Code:
    #Version 15.1
    webuse nhanes2, clear
    
    regress bmi female##region
    
    mat a1=e(b)'
    mat b1=e(V)
    mat c1=(a1,b1)
    mat list c1
    
    loc beta1=c1[2,1]
    loc beta2=c1[12,1]
    loc beta3=c1[4,1]
    
    loc err1=(c1[2,3])
    loc err2=(c1[12,13])
    loc err3=(c1[4,5])
    
    loc cov1=c1[12,3]
    loc cov2=c1[4,3]
    loc cov3=c1[12,5]
    
    loc cumb=`beta1'+`beta2'+`beta3'
    loc cumerr=(`err1'+`err2'+`err3'+2*`cov1'+2*`cov2'+2*`cov3')^0.5
    loc cumerrl=`cumb'-invnorm(0.975)*`cumerr'
    loc cumerrh=`cumb'+invnorm(0.975)*`cumerr'
    
    dis `beta1' `beta2' `beta3' `err1' `err2' `err3' `cov1' `cov2' `cov3'
    dis `cumb' `cumerr'
    
    dis "Cumulative effect is `cumb' (`cumerrl', `cumerrh')"
    [EDIT:] I figured it out! It's simply:

    Code:
    lincom 2.region+1.female+1.female#2.region
    Last edited by Zachary Bartsch; 14 Dec 2022, 12:04.
Working...
X