I would like to calculate a correlation matrix with mi-data. I came across the following syntax on the Internet (https://www.stata.com/statalist/arch...7/msg01382.htm).
It works very well, but I miss the p-values. Does everyone have an idea to add the p-values?
Thank you very much,
Jörg
Code:
/***** begin MI correlation ******************/ cap program drop ecorr program ecorr, eclass version 11 syntax [varlist] [if] [in] [aw fw] [, * ] if (`"`weight'"'!="") { local wgt `weight'`exp' } marksample touse corr `varlist' `if' `in' `wgt', `options' tempname b V mata: st_matrix("`b'", vech(st_matrix("r(C)"))') local p = colsof(`b') mat `V' = J(`p',`p',0) local cols: colnames `b' mat rownames `V' = `cols' eret post `b' `V' [`wgt'] , obs(`=r(N)') esample(`touse') eret local cmd ecorr eret local title "Lower-diagonal correlation matrix" eret local vars "`varlist'" end cap program drop micorr program micorr, rclass tempname esthold _estimates hold `esthold', nullok restore qui mi estimate, cmdok: ecorr `0' tempname C_mi mata: st_matrix("`C_mi'", invvech(st_matrix("e(b_mi)")')) mat colnames `C_mi' = `e(vars)' mat rownames `C_mi' = `e(vars)' di di as txt "Multiple-imputation estimate of the correlation matrix" di as txt "(obs=" string(e(N_mi),"%9.0g") ")" matlist `C_mi' return clear ret matrix C_mi = `C_mi' end sysuse auto, clear set seed 12345 replace mpg = . if runiform()>0.9 mi set wide mi register imputed mpg weight price mi impute mvn mpg weight price, add(20) micorr mpg weight price
0 Response to correlation matrix after multiple imputation with p-values
Post a Comment