libname TIMSS ‘C:UsershhbhcDesktop2011 TIMSSFour-Grade Data 2’;
libname here ‘.’;
data country;
set _null_;
run;
data means;
set _null_;
run;
%macro country(country);
data stu_ach;
set TIMSS.asa&country.m5;
run;
data home_bck;
set TIMSS.ash&country.m5;
run;
data stu_bck;
set TIMSS.asg&country.m5;
run;
/***************sort merge***************/
proc sort data=stu_ach;
by IDSTUD;
run;
proc sort data=home_bck;
by IDSTUD;
run;
proc sort data=stu_bck;
by IDSTUD;
run;
data sch_bck;
set TIMSS.acg&country.m5;
run;
proc sort data=sch_bck;
by IDSCHOOL;
run;
data timss;
merge stu_ach home_bck stu_bck;
by IDSTUD;
run;
proc sort data=timss; by IDSCHOOL IDSTUD;
run;
data timss;
merge sch_bck timss;
by IDSCHOOL ;
run;
data timss;
set timss;
keep ASBG01 /*GENSEX OF STUDENT*/
ASBG03 /*GENOFTEN SPEAK <LANG OF TEST> AT HOME*/
ASBG04 /*GENAMOUNT OF BOOKS IN YOUR HOME*/
ASBG05A /*GENHOME POSSESSCOMPUTER*/
ASBG05B /*GENHOME POSSESSSTUDY DESK*/
ASBG05C /*GENHOME POSSESSBOOKS*/
ASBG05D /*GENHOME POSSESSOWN ROOM*/
ASBG05E /*GENHOME POSSESSINTERNET CONNECTION*/
ASBG05F /*GENHOME POSSESS<COUNTRY SPECIFIC>*/
ASBG05G /*GENHOME POSSESS<COUNTRY SPECIFIC>*/
ASBG05H /*GENHOME POSSESS<COUNTRY SPECIFIC>*/
ASBG05I /*GENHOME POSSESS<COUNTRY SPECIFIC>*/
ASBG05J /*GENHOME POSSESS<COUNTRY SPECIFIC>*/
ASBG05K /*GENHOME POSSESS<COUNTRY SPECIFIC>*/
ASBG07A /*GENHOW OFTENHOMEPARENTS ASK LEARNING*/
ASBG07B /*GENHOW OFTENHOMETALKING ABOUT SCHOOL*/
ASBG07C /*GENHOW OFTENHOMEPARENTS MAKE SURE*/
ASBG07D /*GENHOW OFTENHOMEPARENTS CHECK HOMEWOR*/
IDSTUD /*STUDENT ID*/
IDSCHOOL
IDCLASS
IDCNTRY
ASMMAT01 /*1ST PLAUSIBLE VALUE MATHEMATICS*/
ASMMAT02 /*2ND PLAUSIBLE VALUE MATHEMATICS*/
ASMMAT03 /*3RD PLAUSIBLE VALUE MATHEMATICS*/
ASMMAT04 /*4TH PLAUSIBLE VALUE MATHEMATICS*/
ASMMAT05 /*5TH PLAUSIBLE VALUE MATHEMATICS*/
ASSSCI01 /*1ST PLAUSIBLE VALUE SCIENCE*/
ASSSCI02 /*2ND PLAUSIBLE VALUE SCIENCE*/
ASSSCI03 /*3RD PLAUSIBLE VALUE SCIENCE*/
ASSSCI04 /*4TH PLAUSIBLE VALUE SCIENCE*/
ASSSCI05 /*5TH PLAUSIBLE VALUE SCIENCE*/
ASBH06A /*How well could your child recognize most of the letters of the alphabet when he/she began primary/elementary school?*/
ASBH06B /*How well could your child read some words when he/she began primary/elementary school? */
ASBH06C /*How well could your child read sentences when he/she began primary/elementary school?*/
ASBH06D /*How well could your child write letters of the alphabet when he/she began primary/elementary school?*/
ASBH06E /*How well could your child write some words when he/she began primary/elementary school?*/
ASBH07A /*Could your child count by himself/herself when he/she began primary/elementary school?*/
ASBH07B /*Could your child recognize different shapes when he/she began primary/elementary school?*/
ASBH07C /*Could your child recognize the written numbers from 1?0 when he/she began primary/elementary school?*/
ASBH07D /*Could your child write the numbers from 1?0 when he/she began primary/elementary school?*/
ASBH07E /*Could your child do simple addition when he/she began primary/elementary school?*/
ASBH09A /*how often do you or someone in your home discuss your child’s school work with her*/
ASBH09B /*How often do you or someone in your home help your child with his/her homework?*/
ASBH09C /*How often do you or someone in your home make sure your child sets aside time to do his/her homework?*/
ASBH09D /*How often do you or someone in your home ask your child what he/she learned in school?*/
ASBH09E /*How often do you or someone in your home check if your child has done his/her homework?*/
ASBH09F /*How often do you or someone in your home help your child practice his/her reading?*/
ASBH09G /*How often do you or someone in your home help your child practice his/her math skills?*/
ASBH09H /*How often do you or someone in your home talk with your child about what he/she is reading?*/
/*culture capital: reading time*/
ASBH11 /*how much time you read 1(less than an hour), 2, 3, 4(more than 10 hours), four categories*/
ASBH12 /*how often do you read for you own enjoyment, 1(everyday),2,3,4(never)*/
/*culture capital-reading activities*/
ASBH13A /*How much do you agree that you read only if you have to?*/
ASBH13B /*How much do you agree that you like talking about what you have read with other people?*/
ASBH13C /*How much do you agree that you like to spend your spare time reading?*/
ASBH13D /*How much do you agree that you read only if you need information?*/
ASBH13E /*How much do you agree that reading is an important activity in your home?*/
ASBH13F /*How much do you agree that you would like to have more time for reading?*/
ASBH13G /*How much do you agree that you enjoy reading?*/
/*culture capital possession of books*/
ASBH14 /*how many books at home 1(0-10), 2, 3, 4, 5(>200)*/
/*culture capital-education, parental education*/
ASBH17A /*father’s education*/
ASBH17B /*mother’s education*/ /* 1 NO SCH
2 <ISCED 1 OR 2>
3 <ISC 2>
4 <ISC 3>
5 <ISC 4>
6 <ISC 5B>
7 <ISC 5A,1ST DEG>
8 BEYOND <ISC 5A,1ST DEG>
9 NOT APPLICABLE
99 omitted or invalid
98 not admin.*/
/*culture capital-education expectation*/
ASBH18 /*How far in his/her education do you expect your child to go?*/
/* 6 categories: same as 3-8 of father’s or mother’s education*/
ACBG01 /*total enrollment of students?*/
/* 99999 omitted or invalid; 99998 not admin.VLD: (ACBG01>=1.AND.ACBG01<=11000)*/
ACBG03A /*what percentage of students in your school come from economically disadvantaged families*/
/* 1 0 TO 10%; 2 11 TO 25%; 3 26 TO 50%; 4 MORE THAN 50%; 9 omitted or invalid;8 not admin*/
ACBG04 /*native language as the test language*/
/*1 MORE THAN 90%; 2 76 TO 90%; 3 51 TO 75%; 4 26 TO 50%; 5 25% OR LESS; 9 omitted or invalid; 8 not admin*/
ACBG05A /*How many people live in this area*/
/* MORE THAN 500000 PEOPLE; 2 100001 TO 500000 PEOPLE;3 50001 TO 100000 PEOPLE
4 15001 TO 50000 PEOPLE; 5 3001 TO 15000 PEOPLE; 6 3000 PEOPLE OR FEWER
9 omitted or invalid; 8 not admin*/
ACBG06A /*how many days per year is your school open for instruction*/
/*VLD: (ACBG06A>=150.AND.ACBG06A<=280); 999 missing; 998 not admin*/
ACBG06BA /*what is the total instruction time(hours), excluding breaks, in a typical day*/
/*VLD: (ACBG06BA>=3.AND.ACBG06BA<=10); 99 missing; 98 not admin*/
SENWGT /*SENATE WEIGHT*/
TOTWGT /*TOTAL STUDENT WEIGHT*/
WGTADJ1 /*SCHOOL WEIGHT ADJUSTMENT*/
WGTADJ2 /*CLASS WEIGHT ADJUSTMENT*/
WGTADJ3 /*STUDENT WEIGHT ADJUSTMENT*/
WGTFAC1 /*SCHOOL WEIGHT FACTOR*/
WGTFAC2 /*CLASS WEIGHT FACTOR*/
WGTFAC3 /*STUDENT WEIGHT FACTOR*/
;
run;
data timss;
set timss;
gender=. ;
if ASBG01=1 then gender=0;
if ASBG01=2 then gender=1; /*check*/
langu=. ;
if ASBG03=3 then langu_1=0;
if ASBG03=2 or ASBG03=1 then langu_1=1;
compu=. ;
if ASBG05A=1 then compu=1;
if ASBG05A=2 then compu=0; /*GENHOME POSSESSCOMPUTER*/
desk=. ;
if ASBG05B=1 then desk=1;
if ASBG05B=2 then desk=0; /*GENHOME POSSESSSTUDY DESK*/
book=. ;
if ASBG05C=1 then book=1;
if ASBG05C=2 then book=0; /*GENHOME POSSESSBOOKS*/
room=. ;
if ASBG05D=1 then room=1;
if ASBG05D=2 then room=0; /*GENHOME POSSESSOWN ROOM*/
internet=. ;
if ASBG05E=1 then internet=1;
if ASBG05E=2 then internet=0; /*GENHOME POSSESSINTERNET CONNECTION*/
cntry_1=. ;
if ASBG05F=1 then cntry_1=1;
if ASBG05F=2 then cntry_1=0; /*GENHOME POSSESS<COUNTRY SPECIFIC>*/
cntry_2=. ;
if ASBG05G=1 then cntry_2=1;
if ASBG05G=2 then cntry_2=0; /*GENHOME POSSESS<COUNTRY SPECIFIC>*/
cntry_3=. ;
if ASBG05H=1 then cntry_3=1;
if ASBG05H=2 then cntry_3=0; /*GENHOME POSSESS<COUNTRY SPECIFIC>*/
/*home questionnaire parental involvment items*/
par_inva=. ;
if ASBH09A=1 then par_inva=3;
if ASBH09A=2 then par_inva=2;
if ASBH09A=3 then par_inva=1;
if ASBH09A=4 then par_inva=0;
par_invb=. ;
if ASBH09B=1 then par_invb=3;
if ASBH09B=2 then par_invb=2;
if ASBH09B=3 then par_invb=1;
if ASBH09B=4 then par_invb=0;
par_invc=. ;
if ASBH09C=1 then par_invc=3;
if ASBH09C=2 then par_invc=2;
if ASBH09C=3 then par_invc=1;
if ASBH09C=4 then par_invc=0;
par_invd=. ;
if ASBH09D=1 then par_invd=3;
if ASBH09D=2 then par_invd=2;
if ASBH09D=3 then par_invd=1;
if ASBH09D=4 then par_invd=0;
par_inve=. ;
if ASBH09E=1 then par_inve=3;
if ASBH09E=2 then par_inve=2;
if ASBH09E=3 then par_inve=1;
if ASBH09E=4 then par_inve=0;
par_invf=. ;
if ASBH09F=1 then par_invf=3;
if ASBH09F=2 then par_invf=2;
if ASBH09F=3 then par_invf=1;
if ASBH09F=4 then par_invf=0;
par_invg=. ;
if ASBH09G=1 then par_invg=3;
if ASBH09G=2 then par_invg=2;
if ASBH09G=3 then par_invg=1;
if ASBH09G=4 then par_invg=0;
par_invh=. ;
if ASBH09H=1 then par_invh=3;
if ASBH09H=2 then par_invh=2;
if ASBH09H=3 then par_invh=1;
if ASBH09H=4 then par_invh=0;
/*culture capital reading time*/
par_readt=. ;
if ASBH11=1 then par_readt=0;
if ASBH11=2 then par_readt=1;
if ASBH11=3 then par_readt=2;
if ASBH11=4 then par_readt=3;
/*culture capital reading attitude*/
par_reada=. ;
if ASBH13A=1 then par_reada=0;
if ASBH13A=2 then par_reada=1;
if ASBH13A=3 then par_reada=2;
if ASBH13A=4 then par_reada=3;
par_readb=. ;
if ASBH13B=1 then par_readb=3;
if ASBH13B=2 then par_readb=2;
if ASBH13B=3 then par_readb=1;
if ASBH13B=4 then par_readb=0;
par_readc=. ;
if ASBH13C=1 then par_readc=3;
if ASBH13C=2 then par_readc=2;
if ASBH13C=3 then par_readc=1;
if ASBH13C=4 then par_readc=0;
par_readd=. ;
if ASBH13D=1 then par_readd=0;
if ASBH13D=2 then par_readd=1;
if ASBH13D=3 then par_readd=2;
if ASBH13D=4 then par_readd=3;
par_reade=. ;
if ASBH13E=1 then par_reade=3;
if ASBH13E=2 then par_reade=2;
if ASBH13E=3 then par_reade=1;
if ASBH13E=4 then par_reade=0;
par_readf=. ;
if ASBH13F=1 then par_readf=3;
if ASBH13F=2 then par_readf=2;
if ASBH13F=3 then par_readf=1;
if ASBH13F=4 then par_readf=0;
par_readg=. ;
if ASBH13G=1 then par_readg=3;
if ASBH13G=2 then par_readg=2;
if ASBH13G=3 then par_readg=1;
if ASBH13G=4 then par_readg=0;
/*culture capital possesion of books*/
par_book=. ;
if ASBH14=1 then par_book=0;
if ASBH14=2 then par_book=1;
if ASBH14=3 then par_book=2;
if ASBH14=4 then par_book=3;
if ASBH14=5 then par_book=4;
/*culture capital parental education*/
par_eduf=. ;
if ASBH17A=1 then par_eduf=0;
if ASBH17A=2 then par_eduf=1;
if ASBH17A=3 then par_eduf=2;
if ASBH17A=4 then par_eduf=3;
if ASBH17A=5 then par_eduf=4;
if ASBH17A=6 then par_eduf=5;
if ASBH17A=7 then par_eduf=6;
if ASBH17A=8 then par_eduf=7;
par_edum=. ;
if ASBH17B=1 then par_edum=0;
if ASBH17B=2 then par_edum=1;
if ASBH17B=3 then par_edum=2;
if ASBH17B=4 then par_edum=3;
if ASBH17B=5 then par_edum=4;
if ASBH17B=6 then par_edum=5;
if ASBH17B=7 then par_edum=6;
if ASBH17B=8 then par_edum=7;
/*culture capital expectation of kid’s education*/
par_exp=. ;
if ASBH18=1 then par_exp=0;
if ASBH18=2 then par_exp=1;
if ASBH18=3 then par_exp=2;
if ASBH18=4 then par_exp=3;
if ASBH18=5 then par_exp=4;
if ASBH18=6 then par_exp=5;
sch_siz=. ;
if ACBG01>=1 and ACBG01<=11000 then sch_siz=ACBG01;
disadv=. ;
if ACBG03A=1 then disadv=3;
if ACBG03A=2 then disadv=2;
if ACBG03A=3 then disadv=1;
if ACBG03A=4 then disadv=0;
sch_lan=. ;
if ACBG04=1 then sch_lan=4;
if ACBG04=2 then sch_lan=3;
if ACBG04=3 then sch_lan=2;
if ACBG04=4 then sch_lan=1;
if ACBG04=5 then sch_lan=0;
popul=. ;
if ACBG05A=1 then popul=5;
if ACBG05A=2 then popul=4;
if ACBG05A=3 then popul=3;
if ACBG05A=4 then popul=2;
if ACBG05A=5 then popul=1;
if ACBG05A=6 then popul=0;
run;
data timss (rename=(ASMMAT01=PV1MAT ASMMAT02=PV2MAT ASMMAT03=PV3MAT ASMMAT04=PV4MAT ASMMAT05=PV5MAT
ASSSCI01=PV1SCI ASSSCI02=PV2SCI ASSSCI03=PV3SCI ASSSCI04=PV4SCI ASSSCI05=PV5SCI));
set WORK.timss ;
run;
data timss;
set WORK.timss;
PV_MATH = mean(PV1MAT, PV2MAT, PV3MAT, PV4MAT, PV5MAT);
PV_SCIE = mean(PV1SCI, PV2SCI, PV3SCI, PV4SCI, PV5SCI);
SES_ST = sum(compu, desk, book, room, internet, cntry_1, cntry_2, cntry_3);
PAR_INV = sum(par_inva, par_invb, par_invc, par_invd, par_inve, par_invf, par_invg, par_invh);
PAR_READ = sum(par_reada, par_readb, par_readc, par_readd, par_reade, par_readf, par_readg);
PAR_EDU = sum(par_eduf, par_edum);
run;
proc means data=timss nmiss N min max mean std;
var PV_MATH PV_SCIE gender PAR_INV SES_ST
PAR_READT PAR_READ PAR_BOOK PAR_EDU PAR_EXP
sch_siz disadv sch_lan popul;
run;
/*
proc univariate data=timss plot normal;
var PV1MAT PV2MAT PV3MAT PV4MAT PV5MAT
PV1SCI PV2SCI PV3SCI PV4SCI PV5SCI
gender PAR_INV SES_ST
PAR_READT PAR_READ PAR_BOOK PAR_EDU PAR_EXP
sch_siz disadv sch_lan popul
;
run;
*/
proc mi data=timss
seed=501 noprint out=timss1;
var gender PAR_INV SES_ST
PAR_READT PAR_READ PAR_BOOK PAR_EDU PAR_EXP
sch_siz disadv sch_lan popul
;
run;
proc means data=timss1 nmiss N min max mean std;
var PV_MATH PV_SCIE gender PAR_INV SES_ST
PAR_READT PAR_READ PAR_BOOK PAR_EDU PAR_EXP
sch_siz disadv sch_lan popul;
run;
/************ARRAY TO MAKE SURE THE*****************
*************IMPUTED IS NOT OUT OF RANGE************
****************************************************/
/*ARRAY GENDER*/
data timss1 ;
set timss1;
array fixup(1)
gender ;
do i=1 ;
if (fixup(i) LT 0) then fixup(i)= 0;
if (fixup(i) GT 1) then fixup(i)= 1;
fixup(i)=round(fixup(i));
end;
run;
/*ARRAY PAR_INV*/
data timss1 ;
set timss1;
array fixup(1)
PAR_INV;
do i=1;
if (fixup(i) LT 0) then fixup(i)= 18;
if (fixup(i) GE 24) then fixup(i)=18;
fixup(i)=round(fixup(i));
end;
run;
/*ARRAY SES_ST*/
data timss1 ;
set timss1;
array fixup(1)
SES_ST ;
do i=1 ;
if (fixup(i) LT 0) then fixup(i)= 5;
if (fixup(i) GE 8) then fixup(i)= 5;
fixup(i)=round(fixup(i));
end;
run;
data timss1 ;
set timss1;
array fixup(1)
PAR_READT ;
do i=1 ;
if (fixup(i) LT 0) then fixup(i)= 1;
if (fixup(i) GE 3) then fixup(i)= 1;
fixup(i)=round(fixup(i));
end;
run;
data timss1 ;
set timss1;
array fixup(1)
PAR_READ ;
do i=1 ;
if (fixup(i) LT 0) then fixup(i)= 14;
if (fixup(i) GE 21) then fixup(i)=14;
fixup(i)=round(fixup(i));
end;
run;
data timss1 ;
set timss1;
array fixup(1)
PAR_BOOK ;
do i=1 ;
if (fixup(i) LT 0) then fixup(i)= 2;
if (fixup(i) GE 4) then fixup(i)= 2;
fixup(i)=round(fixup(i));
end;
run;
data timss1 ;
set timss1;
array fixup(1)
PAR_EDU ;
do i=1 ;
if (fixup(i) LT 0) then fixup(i)= 5 ;
if (fixup(i) GE 14) then fixup(i)=5 ;
fixup(i)=round(fixup(i));
end;
run;
data timss1 ;
set timss1;
array fixup(1)
PAR_EXP ;
do i=1 ;
if (fixup(i) LT 0) then fixup(i)= 4 ;
if (fixup(i) GE 5) then fixup(i)= 4 ;
fixup(i)=round(fixup(i));
end;
run;
data timss1 ;
set timss1;
array fixup(1)
sch_siz ;
do i=1 ;
if (fixup(i) LT 169) then fixup(i)= 755;
if (fixup(i) GE 1469) then fixup(i)=755;
fixup(i)=round(fixup(i));
end;
run;
data timss1 ;
set timss1;
array fixup(1)
disadv ;
do i=1 ;
if (fixup(i) LT 0) then fixup(i)= 1;
if (fixup(i) GE 3) then fixup(i)= 1;
fixup(i)=round(fixup(i));
end;
run;
data timss1 ;
set timss1;
array fixup(1)
sch_lan ;
do i=1 ;
if (fixup(i) LT 0) then fixup(i)=4;
if (fixup(i) GE 4) then fixup(i)=4;
fixup(i)=round(fixup(i));
end;
run;
data timss1 ;
set timss1;
array fixup(1)
popul ;
do i=1 ;
if (fixup(i) LT 1) then fixup(i)=4;
if (fixup(i) GE 5) then fixup(i)=4;
fixup(i)=round(fixup(i));
end;
run;
proc sort data=timss1; by IDSCHOOL;
proc means data = timss1 noprint;
var sch_siz disadv sch_lan popul;
output out=temp mean= Mch_siz Misadv Mch_lan Mopul;
by IDSCHOOL;
run;
proc means data=temp;
var Mch_siz Misadv Mch_lan Mopul;
run;
proc sort data=timss1; by IDSCHOOL;
proc sort data=temp; by IDSCHOOL;
data timss1;
merge timss1
temp;
by IDSCHOOL;
run;
/**************************************
**************HLM*********************
**************************************/
data TIMSS2011 (drop = i);
set timss1;
array testmiss(*) _numeric_;
do i = 1 to dim(testmiss);
if testmiss(i) = . then testmiss(i) = 9999;
if testmiss(i) ne . then testmiss(i) = testmiss(i)*1.0000;
end;
run;
%macro impute(num);
data TIMSS2011#
set TIMSS2011(where = (_Imputation_ = &num));
MATH=PV&num.MAT;
SCI =PV&num.SCI;
run;
data TIMSS2011#
set TIMSS2011&num (keep =
IDSCHOOL IDSTUD
MATH PV1MAT PV2MAT PV3MAT PV4MAT PV5MAT
SCI PV1SCI PV2SCI PV3SCI PV4SCI PV5SCI
gender PAR_INV SES_ST
PAR_READT PAR_READ PAR_BOOK PAR_EDU PAR_EXP
Mch_siz Misadv Mch_lan Mopul
TOTWGT _Imputation_);
proc means data = TIMSS2011#
data TIMSS2011#
array fixorder IDSCHOOL IDSTUD
MATH PV1MAT PV2MAT PV3MAT PV4MAT PV5MAT
SCI PV1SCI PV2SCI PV3SCI PV4SCI PV5SCI
gender PAR_INV SES_ST
PAR_READT PAR_READ PAR_BOOK PAR_EDU PAR_EXP
Mch_siz Misadv Mch_lan Mopul
TOTWGT _Imputation_;
set TIMSS2011#
data here.TIMSS2011#
set TIMSS2011#
run;
proc export data= here.TIMSS2011&num
outfile= “TIMSS2011&num..dat”
dbms=tab replace;
putnames = no;
run;
%mend impute;
%impute(1);
%impute(2);
%impute(3);
%impute(4);
%impute(5);
%mend country;
%country(hkg);