Hi,
I have a program that allows the user to obtain standardised differences (raw and weighted) after using propensity scores. I would like my program to report the standardised differences for each of the variables that I have entered into the program. I am looking for guides/articles online that show how to generically display results after writing a program but none that I can find are very helpful.
My program is:
I would like to be able to have two main columns: one for the standardised differences and one for the variance ratios. Ideally, each of these main columns would have two subcolumns (i.e., one subcolumn for the "Raw", and one column for the "Weighted"). This is something similar to the way the command "tebalance summarize" reports results:

Any help is much appreciated!
I have a program that allows the user to obtain standardised differences (raw and weighted) after using propensity scores. I would like my program to report the standardised differences for each of the variables that I have entered into the program. I am looking for guides/articles online that show how to generically display results after writing a program but none that I can find are very helpful.
My program is:
Code:
capture program drop myprogramme
program define myprogramme
syntax varlist(numeric fv)
* Create macros from the varlist
tokenize `varlist'
local outcome `1'
macro shift
local exposure `1'
macro shift
local varlist `*'
* Create the IPW weights
capture drop _ipw
qui gen _ipw = .
qui replace _ipw = (`exposure'==1) / _ps if `exposure'==1
qui replace _ipw = (`exposure'==0) / (1- _ps) if `exposure'==0
* Calculate the covariate balance
foreach var in `varlist' {
* Raw SMD
qui summarize `var' if `exposure'==1
local m1: di %9.7g r(mean)
local v1: di %9.7g r(Var)
qui summarize `var' if `exposure'==0
local m0: di %9.7g r(mean)
local v0: di %9.7g r(Var)
* Calculate the Standardised "mean difference"
di as text "Raw SMD: " as text "`var' " %9.7g (`m1' - `m0') / sqrt( (`v1' + `v0') /2 )
* Weighted SMD
qui summarize `var' [iw=_ipw] if `exposure'==1
local m1: di %9.7g r(mean)
local v1: di %9.7g r(Var)
qui summarize `var' [iw=_ipw] if `exposure'==0
local m0: di %9.7g r(mean)
local v0: di %9.7g r(Var)
* Calculate the Standardised "mean difference"
di as text "Weighted SMD: " as text "`var' " %9.7g (`m1' - `m0') / sqrt( (`v1' + `v0') /2 )
* Raw VR
qui sum `var' if `exposure' ==1
local v1: di %9.7g r(Var)
qui sum `var' if `exposure' ==0
local v0: di %9.7g r(Var)
* Calculate the variance ratio
di as text "Raw VR: " as text "`var' " %9.7g `v1' / `v0'
* Weighted VR
qui sum `var' [iw=_ipw] if `exposure' ==1
local v1: di %9.7g r(Var)
qui sum `var' [iw=_ipw] if `exposure' ==0
local v0: di %9.7g r(Var)
* Calculate the variance ratio
di as text "Weighted VR: " as text "`var' " %9.7g `v1' / `v0'
}
end
I would like to be able to have two main columns: one for the standardised differences and one for the variance ratios. Ideally, each of these main columns would have two subcolumns (i.e., one subcolumn for the "Raw", and one column for the "Weighted"). This is something similar to the way the command "tebalance summarize" reports results:
Any help is much appreciated!

Comment