Hello All, I have intensive longitudinal data with many observations per individual. I am running multiple regression models by individual and extracting both (1) parameter estimates and (2) the variance-covariance matrix for these estimates into a separate dataset. I am looking to turn the variance-covariance matrix into a vector of columns, with each column containing just one of the matrix elements from the bottom half of the matrix (including the diagonal). I am able to achieve this for one individual using the following PROC IML code. Here is the variance-covariance matrix of the estimates for individual 1 (what I start with). Here is the code I used: proc iml;
use cov_id1; /*cov_id1 is the name of the dataset output from the proc reg ods output statement requesting covb */
read all var _num_ into cov1[r=Variable c=VarNames];
close cov_id1;
print cov1;
cov_vars1 = vech(cov1);
cov_vars_t1 = cov_vars1`;
print cov_vars_t1;
create cov_rows1
from cov_vars_t1[colname={"Int_Int" "Int_t" "Int_CravLag1" "Int_CravLag2"
"t_t" "t_Clag1" "t_Clag2" "Clag1_Clag1" "Clag1_Clag2" "Clag2_Clag2"}];
append from cov_vars_t1;
close cov_rows1;
quit; proc print data=cov_rows1 noobs; run; Which produces this result for individual 1: HOWEVER, I am hitting a wall trying to get PROC IML to loop through each participant and output a row of matrix elements for each individual in the study (N = 200). Does anyone have ideas for how to improve this code to allow me to create a dataset that has one row, marked with the ID, for each individual, and contains all of the unique variance-covariance matrix elements in separate columns for that individual? I have attached a snippet of the data I am working with. As you can see, some of the elements will be missing for some individuals (see ID = 6), in case that complicates things. Thank you.
... View more