Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Correlation matrices using multiply imputed datasets


From   Mosi Ifatunji <[email protected]>
To   [email protected]
Subject   st: Correlation matrices using multiply imputed datasets
Date   Mon, 21 Oct 2013 17:29:14 -0400

Colleagues,

I have been asked by reviewers to include a correlation matrix of my key independent variables. My analysis employed multiple imputation so I will need to generate correlation matrices using multiply imputed data.

Some time ago I wrote the list asking about this and was generously provided with the following two fixes:

First, someone offered that I could obtain the estimates using the the -mi- command set, using:

	mi convert wide, clear
	mi register imputed employ lperinc educ1 educ2 educ3 educ4 workexp motivation efficacy ysm
	mi impute mvn employ lperinc educ2 educ3 educ4 workexp motivation efficacy ysm, emonly
	mat Sigma = r(Sigma_em) /* save EM estimate of the variance-covariance (VC) matrix */
	_getcovcorr Sigma, corr shape(full)   /* convert VC to a correlation matrix */
	mat C = r(C)
	matlist C

This works fine but ends up excluding the first education category from the correlation matrix and does not include standard errors or tests of statistical significance.

The second strategy was to write a short program, creating a new command -micorr- :

	cap program drop ecorr
	program ecorr, eclass
		version 12
		syntax [varlist] [if] [in] [aw fw] [, * ]
		if (`"`weight'"'!="") {
			local wgt `weight'`exp'
		}
		marksample touse
		correlate `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

Then use the new command to generate estimates:

	micorr employ lperinc educ1 educ2 educ3 educ4 workexp motivation efficacy ysm

This also works fine. The estimates between the two strategies are the same; very confirming :-) This second way has the advantage of providing me with the estimate for the first education category. However, it also does not provide me with estimates of the standard errors or tests of significance.

Although I am fairly proficient at using Stata I have not progressed to the level of programming my own commands. I am hoping that someone might be able to edit either of the two above strategies (preferably the second) in a way that provides the user with estimates of the standard error and/or tests of statistical significance?

Any help would be greatly appreciated.

Best,

-- Mosi
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index