Hello There,
I am currently trying to transpose my regression results (i.e having one model in a row instead of a column) and output it into Latex, adding SE in parentheses and Pvalue in bracket. We're not trying to indicate significant coeff using stars and instead trying to add columns of p values for each coefficient next to the column of S.E.
The trasponse program I am using is:
cap prog drop transpose
prog def transpose
matrix C = r(coefs)
matrix S = r(stats)
eststo clear
local rnames : rownames C
local models : coleq C
local models : list uniq models
local i 0
foreach name of local rnames {
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 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'
}
local snames : rownames S
local i 0
foreach name of local snames {
local ++i
local j 0
capture matrix drop b
foreach model of local models {
local ++j
matrix tmp = S[`i', `j']
matrix colnames tmp = `model'
matrix b = nullmat(b), tmp
}
ereturn post b
eststo `name'
}
end
My regression code is:
est clear
foreach y of global outcomes {
reg `y' msg1 msg2 msg3, r
sum `y' if e(sample) == 1 & msg4==1
local mean = r(mean)
eststo `y': reg `y' msg1 msg2 msg3, r
test msg1= msg2
estadd scalar test1 = r(p)
test msg2= msg3
estadd scalar test2 = r(p)
test msg1= msg3
estadd scalar test3 = r(p)
estadd local empty " "
estadd scalar ymean = `mean'
}
esttab, cells(b(fmt(%8.3f)) se(par(`" ("' `")"') fmt(%8.3f)) p(fmt(%8.3f) par(`" ["' `"]"'))) nostar ///
stats(test1 test2 test3 ymean N) ///
keep(msg1 msg2 msg3 ) ///
order(msg1 msg2 msg3)
transpose
esttab using "$tables/latex/reg_table.tex" ///
, b(%16.3f) se(%16.3f) p(%16.3f) noobs compress nonumb collabels(none) ///
nonotes nogaps replace ${refcatall} wide ///
nostar ///
nomtitles prehead(%) posthead(%) ///
varlabel($labelvars) fragment
When I run this, I receive an error message:
only one allowed of z, se, p, ci, and aux()
r(198);
I tried to add a matrix for pvalue in the tranpose program but failed to fix the error. I would greatly appreciate if anyone knows how to add columns of "pvalues" in bracket (e.g. [0.001]) next to the column of s.e. for each coefficient! Thank you!
Related Posts with Transpose regression table, adding S.E. and P value
How to run seemingly unrelated regressions (SUR) in a multilevel model?Hello I am trying to use seemingly unrelated regressions (SUR) technique in a 2-level model which i…
How to compute intraday stock returnsHi, I'm new to Stata. Probably this question has already been answered, but I couldn't locate it. I…
Opt-out alternative for Choice ExperimentsHey everyone, I am new to stata and CE and I hope some one can help me how to include opt-out optio…
PSM help: using observation # stubs to generate dummiesHi All. I’d love some help with the PSM dataset I’m constructing. I’ve already established overlap a…
stset use with multiple records per personHi, I'm relatively new to Stata and am trying to set up some data for a Cox regression. I have abou…
Subscribe to:
Post Comments (Atom)
0 Response to Transpose regression table, adding S.E. and P value
Post a Comment