Hi All,
So here's what i have developed thus far in response to my question below, using the sample file created using:
data _null_; set sample; file "C:\Users\Jason\Desktop\sample.txt"; put teacherid student_id schoolid post_classman_ability post_pck_ability; file print; put teacherid student_id schoolid post_classman_ability post_pck_ability; run;
If i correlate two variables using all available data (including duplicate level-2 values), i get a correlation of -.12783.
**correlation between two retaining all data; proc corr data=sample; var post_classman_ability post_pck_ability; run;
If i use a mixed model with the student-level variable as the DV and the teacher as the IV, obtaining the var-covariance matrix of fixed effects (which includes an intercept and the post_pck_ability predictor fixed effects), i can then use that covariance matrix to calculate the cross-level correlation as specified in the link in the original post.
**model with student-level measure as dv and teacher-level measure as iv; proc mixed data=tssc_y1 method=ml; class schoolid; model post_classman_ability = post_pck_ability/ solution corrb covb; random intercept/ subject=teacherid type=un; ods output covb=covb; run;
The IML syntax below attempts to calculate the cross-level correlation, obtaining a value of -.057711. I'm glad to see the sign in the same direction, but i'm wondering if the decrease from -.12 down to .-05 seems reasonable, of if i'm missing something.
**correlation from covariance; proc iml; use covb; read all var {Col1 Col2} into cov_mat[colname=varNames]; print cov_mat; start Cov2Corr(S); **grab the variances of each variable; var_mat=(vecdiag(S))`; *print var_mat; **caculate sd by taking square root of product; prod_sd=sqrt(var_mat[1,1]#var_mat[1,2]); *print prod_sd; **divide each element of covariance matrix by the prod_sd, focus on covariance cells; r_mat=S/prod_sd; r=r_mat[1,ncol(r_mat)]; return R; finish; r=Cov2Corr(cov_mat);
n=861; t=sqrt(n-2)*sqrt((r*r)/(1-r*r)); p_onetail=1-probt(t,n-2); p_twotail=(1-probt(abs(t),n-2))*2; print r p_onetail p_twotail; quit;
... View more