*! version 1.0 20240917

mi_impute_from_get -- Read files and return matrices for external imputation model

Syntax

mi_impute_from_get [, options]

options

Main
b(filename [filename [...]]) list of file names containing the regression coefficients of the imputation model

v(filename [filename [...]]) list of file names containing the variance/covariances of the imputation model

colnames(string) list of variable names included in the linear predictor of the imputation model

tf(string) format of the files (either tab delimited .txt or excel .xlsx)

imodel(string) type of imputation model (qreg, mlogit, logit)

values(numlist) values taken by the categorical variable, if imodel(mlogit), to be imputed

path(string) location of the files

Description

mi_impute_from_get faciliates the use of external imputation models by reading the files and formatting matrices to be passed to mi_impute_from.
If multiple files are specified, mi_impute_from_get combines regression coefficients across files using an inverse-variance weighted
least squares model.

Options

Main

b(string) specifies a list of files containing the estimated regression coefficients for the imputation model for ivar.

v(string) specifies a list of files containing the estimated variance/covariances of the regression coefficients for the imputation model for ivar.

colnames(string) specifies list of variable names (including the constant _cons) included in the linear predictor of the imputation model.

tf(delimited|excel) format of the files (either tab delimited .txt or excel .xlsx) containing the estimated imputation model.
Adding the format (.txt, .xlsx) to each file name in b() and v() is not needed. The default format for all the files is tab delimited (.txt).

imodel(string) the type of imputation model (qreg, mlogit, logit) passed in b(). Of note, for a quantitative variable one has to pass the linear predictor for 99 (q=0.01(.01).99) quantiles of the imputation model. A loop can be used to combine all the estimated linear predictors in a single file.
For a categorical variable with k levels one has to pass k linear predictors of multinomial logistic regression models. The reference outcome level is recognized by the fact that all regression coefficients are equal to zero.

values(numlist) specifies all the numerical values of the categorical variable to be imputed. This is needed when using imodel(mlogit) as imputation model.

path(string) specifies the location of the file names specified in options b() and v().

Example #1: Estimate 99 quantiles of the imputation model for a quantitative variable z

* Export the estimates of imputation models based on quantile regression using Study #2, #3, #4, and #5

quietly forv s = 2/5 {
use http://www.stats4life.se/data/from/qreg_study_`s', clear
qreg z y x c, q(1)
mat ib = e(b)
mat iV = e(V)
forv i = 2/99 {
qreg z y x c, q(`i')
mat ib = ib , e(b)
mata: iV = blockdiag(st_matrix("iV"), st_matrix("e(V)"))
mata: st_matrix("iV", iV)
}
svmat ib
export delimited ib* using e_qreg_b_s`s'.txt in 1 , replace
svmat iV
export delimited iV* using e_qreg_v_s`s'.txt if iV1 != . , replace
}

* Open the Study #1 with missing data on the quantitative variable z

use http://www.stats4life.se/data/from/qreg_study_1, clear
mi set wide
mi register imputed z

* Read the imputation model from just Study #2

mi_impute_from_get , b(e_qreg_b_s2) v(e_qreg_v_s2) ///
colnames(y x c _cons) imodel(qreg) path(http://www.stats4life.se/data/from/)

mat ib = r(get_ib)
mat iV = r(get_iV)

* External imputation using -mi impute from-

mi impute from z , add(10) b(ib) v(iV) imodel(qreg)

* Read the imputation models from Study #2, #3, #4, and #5

mi_impute_from_get , b(e_qreg_b_s2 e_qreg_b_s3 e_qreg_b_s4 e_qreg_b_s5) ///
v(e_qreg_v_s2 e_qreg_v_s3 e_qreg_v_s4 e_qreg_v_s5) ///
colnames(y x c _cons) imodel(qreg) ///
path(http://www.stats4life.se/data/from/)

mat ib = r(get_ib)
mat iV = r(get_iV)

* External imputation using -mi impute from-

mi impute from z , add(10) b(ib) v(iV) imodel(qreg)

Stored results

mi_impute_from_get stores the following in r():

Matrices

r(get_ib) regression coefficients for the imputation model

r(get_iV) var/covariance of the regression coefficients for the imputation model