/*Change the directory names to whereever you put your data sets, allkor and allusa*/
libname here "C:\temp";
*libname library "C:\My Documents";
/*merging Korean and American data and select only 8th garders*/
data both;set here.allkor here.allusa /*here.alljpn*/;
if IDgrader=2;/*8th graders*/
run;
/*Manimulating data such that we have dummy variables,
college=1 when one or two of the parents graduated college; else 0.
Also a dummy variable for boy, 1 if boy, 0 if girl
Just in case I created both categorical and numeric variables. Sometimes this is helpful.
*/;
data both;set both;
/*categorical variables*/
college="high school";
if BSDGEDUP=1 then COLLEGE="2college";
boy="2girl";
if itsex=2 then boy="1boy";
/*numeric variables*/
college2=0;
if BSDGEDUP=1 then COLLEGE2=1;
boy2=0;
if itsex=2 then boy2=1;
run;
/*Check the contents of your data*/
proc contents data=both;
run;
/*Getting school mean variable*/
/*See my SAS manual II to learn this*/
proc sql ; create table both2 as
select*,
mean(BTBMTM10) as homework
from both
group by IDSCHOOL ;
run;
/*Standardizing values*/
/*Z-scores*/
proc standard mean=0 std=1 data=both2 out=both2;
var BSMPV01;
run;
/*School-mean Centering using proc standard*/
proc sort;by IDCNTRY ;
run;
proc standard mean=0 std=1 data=both2 out=both2 ;
by IDCNTRY;
var homework;
run;
/*I forgot why I am doing this*/
/*maybe not necessary*/
proc sort data=both2 out=both2;
by IDcntry;
run;
/*school mean homework time was schewed, so use log to get a better distribution*/
data both2;set both2;
homeworkL=log(homework+1);
run;
/*Checking how the two measures look differently*/
/*I thought both looked somewhat ugly*/
proc univariate data=both2 plot;
var homework homeworkL;run;
/*OLS regression*/
/*by IDcntry--> to run a regression separately by nation*/
proc reg data=both2;
by IDcntry;
model BSMPV01= college2 boy2;
run;
/*HLM*/
/*Anova model or intercept-only model*/
proc mixed data=both2 covtest noclprint;
by IDcntry;
model bsmpv01= / solution ddfm=bw ;
random intercept/ sub= IDSCHOOL ;
run;
/*college and boy as predictors*/
/*Coefficients of these two predictors are set RANDOM*/
proc mixed data=both2 covtest noclprint;
by IDcntry;
class college boy;
model bsmpv01= college boy/ solution ddfm=bw ;
random intercept college boy/ sub= IDSCHOOL s;
ods output solutionR=sol;
run;
/*Above created a data that contains results. The name of the data is SOL, which contains coefficients
obtained for schools*/
/*Eyeball the results*/
proc print data=sol;
where effect="college" and estimate > -9 and DF > -9;
run;
/*Eyeball the results*/
proc univariate data=sol plot;
where effect="college" and estimate > -9 and DF > -9;
by IDcntry;
var estimate;run;
proc mixed data=both2 covtest noclprint;
by IDcntry;
class college boy;
model bsmpv01= college2 boy2 homework/ solution ddfm=bw ;
random intercept college boy/ sub= IDSCHOOL ;
*ods output solutionR=sol;
run;
proc mixed data=both2 covtest noclprint;
by IDcntry;
class college boy;
model bsmpv01= college2 boy2 homework college2*homeworkL / solution ddfm=bw ;
random intercept college boy/ sub= IDSCHOOL ;
*ods output solutionR=sol;
run;