Announcement

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

  • Adding columns in the output produced by esttab

    I am trying to create a regression table with models in each row and my variables of interest in each column. I figured it out for the first two columns. I want to add another column with the sum of coefficients and their standard errors which are saved in local macros sum_coef_1 and se_sum_1 respectively. Similarly, for model 2, it is stored in macros. So how should I add this column to my final output table?




    eststo model1: areg constitutional_rights mc_jan mc_jan_jan janajati mun_jan_share age female i.q104, cl(municipality_code) abs(province_id)
    mat V = e(V)
    local se_sum_1 = round(sqrt(V[1,1] + V[3,3] + 2*V[3,1]), 0.001)
    local sum_coef_1 = _b[mc_jan] + _b[mc_jan_jan]



    eststo model2: areg nepal_future mc_jan mc_jan_jan janajati mun_jan_share age female i.q104, cl(municipality_code) abs(province_id)
    mat(V) = e(V)
    local se_sum_2 = round(sqrt(V[1,1] + V[3,3] + 2*V[3,1]), 0.001)
    local sum_coef_2 = _b[mc_jan] + _b[mc_jan_jan]





    esttab, se nostar stats(mean_jan mean_bcn pv fdr)
    matrix C = r(coefs)
    mat S = r(stats)

    eststo clear

    local ronames mc_jan mc_jan_jan

    local models : coleq C

    local models : list uniq models

    local i 0

    foreach name of local ronames {
    local ++i
    local j 0
    capture matrix drop b
    capture matrix drop se
    foreach model of local models {
    local ++j
    matrix tmp = C[`i', 2*`j'-1]
    if `i'==1 {
    matrix tmp[1,1] = tmp[1,1] * -1
    }
    if tmp[1,1]<. {
    matrix colnames tmp = `model'
    matrix b = nullmat(b), tmp
    matrix tmp[1,1] = C[`i', 2*`j']
    matrix se = nullmat(se), tmp

    }
    }


    ereturn post b
    quietly estadd matrix se
    eststo `name'
    }

    esttab, se mtitle noobs
    Last edited by Daniel Abraham; 31 Aug 2023, 14:05.
Working...
X