Hi all,
I'm working with coefplot in Stata (coefplot is a community-contributed command available from the Stata Journal) and plotting treatment effects for several heterogeneous treatment effect (HTE) variables. Each HTE variable produces two point estimates (e.g. x_hte1 and x_hte2) which I'm plotting side-by-side. I want to label each point with the estimate and the percent change relative to the control group mean. I calculate and store these without any issue, there are 5 vars which each have 2 HTEs so there are 10 total points plotted.
I want to plot BOTH the estimate (@b) AND the percent change, computed as:
foreach hte in `hte_vars' {
estimates restore m_`hte'
matrix B = e(beta_pds)
local ncol = colsof(B)
local b1 = B[1, `=`ncol'-1']
local b0 = B[1, `ncol']
local ctrl1 = `ctrl1_`hte''
local ctrl0 = `ctrl2_`hte''
if `ctrl1' != 0 {
local pct1 = 100 * `b1' / `ctrl1'
}
else {
local pct1 = .
}
if `ctrl0' != 0 {
local pct0 = 100 * `b0' / `ctrl0'
}
else {
local pct0 = .
}
* Format nicely for labels
local lab1 : display %5.3f `b1'
local lab2 : display %5.3f `b0'
local pc1 : display %4.1f `pct1'
local pc0 : display %4.1f `pct0'
* Create quoted label strings
local label1 = `""`lab1', `pc1'%""'
local label2 = `""`lab2', `pc0'%""'
* Append properly quoted strings to mlabel macro
local all_mlabels `"`all_mlabels' `label1' `label2'"'
}
I’ve created the labels as a local macro all_mlabels, and they look great when I display them (fake numbers):
display _asis `"`all_mlabels'"'
"123.000, 123.0%" "456.000, 456.0%" "789.000, 789.0%" "111.000, 111.0%" "222.000, 222.0%" "333.000, 333.0%" "444.000, 444.0%" "555.000, 555.0%" "666.000, 666.0%" "777.000, 777.0%"
But when I try to run:
coefplot ///
(m_hte_var1, rename(x_hte_var11 = "Group 1" x_hte_var12 = "Group 2")) ///
(m_hte_var2, rename(x_hte_var21 = "Group 1" x_hte_var22 = "Group 2")) ///
(m_hte_var3, rename(x_hte_var31 = "Group 1" x_hte_var32 = "Group 2")) ///
(m_hte_var4, rename(x_hte_var41 = "Group 1" x_hte_var42 = "Group 2")) ///
(m_hte_var5, rename(x_hte_var51 = "Group 1" x_hte_var52 = "Group 2")) ///
, mlabels(`all_mlabels') b(beta_pds) v(V_pds) keep(x_*) ///
xline(0) legend(off)
I get the error: mlabels(): invalid matchlist
Which I am very confused by as I have 10 points plotted, and 10 mlabels() stored. I cannot share a sample of the data unfortuantely, but any advice on how to work through this issue would be very appreciated.
Thanks so much in advance.
I'm working with coefplot in Stata (coefplot is a community-contributed command available from the Stata Journal) and plotting treatment effects for several heterogeneous treatment effect (HTE) variables. Each HTE variable produces two point estimates (e.g. x_hte1 and x_hte2) which I'm plotting side-by-side. I want to label each point with the estimate and the percent change relative to the control group mean. I calculate and store these without any issue, there are 5 vars which each have 2 HTEs so there are 10 total points plotted.
I want to plot BOTH the estimate (@b) AND the percent change, computed as:
foreach hte in `hte_vars' {
estimates restore m_`hte'
matrix B = e(beta_pds)
local ncol = colsof(B)
local b1 = B[1, `=`ncol'-1']
local b0 = B[1, `ncol']
local ctrl1 = `ctrl1_`hte''
local ctrl0 = `ctrl2_`hte''
if `ctrl1' != 0 {
local pct1 = 100 * `b1' / `ctrl1'
}
else {
local pct1 = .
}
if `ctrl0' != 0 {
local pct0 = 100 * `b0' / `ctrl0'
}
else {
local pct0 = .
}
* Format nicely for labels
local lab1 : display %5.3f `b1'
local lab2 : display %5.3f `b0'
local pc1 : display %4.1f `pct1'
local pc0 : display %4.1f `pct0'
* Create quoted label strings
local label1 = `""`lab1', `pc1'%""'
local label2 = `""`lab2', `pc0'%""'
* Append properly quoted strings to mlabel macro
local all_mlabels `"`all_mlabels' `label1' `label2'"'
}
I’ve created the labels as a local macro all_mlabels, and they look great when I display them (fake numbers):
display _asis `"`all_mlabels'"'
"123.000, 123.0%" "456.000, 456.0%" "789.000, 789.0%" "111.000, 111.0%" "222.000, 222.0%" "333.000, 333.0%" "444.000, 444.0%" "555.000, 555.0%" "666.000, 666.0%" "777.000, 777.0%"
But when I try to run:
coefplot ///
(m_hte_var1, rename(x_hte_var11 = "Group 1" x_hte_var12 = "Group 2")) ///
(m_hte_var2, rename(x_hte_var21 = "Group 1" x_hte_var22 = "Group 2")) ///
(m_hte_var3, rename(x_hte_var31 = "Group 1" x_hte_var32 = "Group 2")) ///
(m_hte_var4, rename(x_hte_var41 = "Group 1" x_hte_var42 = "Group 2")) ///
(m_hte_var5, rename(x_hte_var51 = "Group 1" x_hte_var52 = "Group 2")) ///
, mlabels(`all_mlabels') b(beta_pds) v(V_pds) keep(x_*) ///
xline(0) legend(off)
I get the error: mlabels(): invalid matchlist
Which I am very confused by as I have 10 points plotted, and 10 mlabels() stored. I cannot share a sample of the data unfortuantely, but any advice on how to work through this issue would be very appreciated.
Thanks so much in advance.
Comment