Hello Statalist, I have been grappling with how to replace a coefficient, standard error, and t-stat in xtscc regression results with lincom estimates prior to creating an esttab table. I am working with Stata version 15.1 and currently do not have the option to update, though I understand from here that more recent versions of Stata might make some of this easier by directly indexing "special" matrices for editing. I have found ways to edit the e(b) and e(V) matrices to replace the coefficient of interest with the lincom estimates, but it seems that the r(table) matrix is what I actually want to edit in order for it to show up in the esttab output. These were the posts I referred to initially when I thought that I wanted to edit the e(b) and e(V) matrices to affect the esttab output:
https://www.stata.com/statalist/arch.../msg00054.html
The basic code for one of the regressions and lincom is
What I would like to do is rather than have the kdd coefficient display the raw coefficient, have it display the aggregate effects, as calculated in the lincom command.
The issue I am running into is that I am not sure how to go about editing r(table). From the link I included above, the only way I found to edit the matrices of the estimation results is as follows:
However, I cannot find an analog repost command for return, only ereturn. I am a little stuck now on how to proceed. I recognize that in newer versions I could probably just use:
but am unsure of what to do in version 15, where that triggers an error.
I have created an example using the Stata dataset auto that I hope will help with reproducibility:
Hopefully I am just missing something rather simple, but any assistance would be appreciated!
https://www.stata.com/statalist/arch.../msg00054.html
The basic code for one of the regressions and lincom is
Code:
* Regression xtscc fao_food_cpi_winsor kdd gdd c.kdd#c.l.agimp_sharegdp_baci i.country_code i.year, fe lag(5) estimates store prices_dom_kdd_impshare * Calculate median in-sample value for interacted term sum l.agimp_sharegdp_baci if _est_prices_dom_kdd_impshare, detail local impshare_median = r(p50) * Calculate aggregate effects for median import share lincom _b[kdd] + _b[c.kdd#c.l.agimp_sharegdp_baci]*`impshare_median' * Store results for use in wrapper scalar coef = r(estimate) scalar se = r(se) scalar t = r(t)
The issue I am running into is that I am not sure how to go about editing r(table). From the link I included above, the only way I found to edit the matrices of the estimation results is as follows:
Code:
cap prog drop wrapper prog wrapper, eclass * Edit coefficient matrix matrix B = e(b) matrix B[1, 1] = coef ereturn repost b = B * Edit variance-covariance matrix matrix SE = e(V) matrix SE[1,1] = se^2 ereturn repost V = SE end
Code:
matrix r(table)[1, 1] = coef
I have created an example using the Stata dataset auto that I hope will help with reproducibility:
Code:
version 15.1 sysuse auto, clear regress price mpg c.mpg#c.headroom estimates store example sum headroom if _est_example, de local med_headroom = r(p50) lincom _b[mpg] + _b[c.mpg#c.headroom]*`med_headroom' scalar coef = r(estimate) scalar se = r(se) scalar t = r(t) estimates replay example
Comment