/* I am adding rash version of mission spirit variable*/ /*I added norm variables (mission sprit) and basic teacher information such as demography Creating two important data sets student data SEITO teacher data SENSEI Using these, apply proc IML I am adding teacher characterisics variables */ /* persoMAX=MAX(of TSperso STperso); persoAVE=MEAN(of TSperso STperso); studyMAX=MAX(of TSstudy STstudy); studyAVE=MEAN(of TSstudy STstudy); clubMAX=MAX(of TSclub STclub); clubAVE=MEAN(of TSclub STclub);*/ *%let zzzzz=clubMAX;/*the types of ties*/ %let zzzzz=persoMAX;/*the types of ties*/ %let newname=PAL; %let chara1=appl ashw awar buss care cohw cove disn disp empc fact furt grou indi intr lect mach maga mate rehw reve rout seat solv supp tv test GETTHRU PREVENT CHANGE CANDO FORWARD DOBEST AGE YEAR MALE FEMALE ASSOC SCIENCE MATH mission ;/*these are teacher practices & mission spirit variable, as well as some demographic and the such*/ %let chara2=; /*also changed variables names from ment to pal*/ libname here "H:\AERAproject"; *libname library "/home/ackmoto/"; *libname dil1 '/home/ackmoto/MOTO/nsf2'; libname dil2 'H:\AERAproject'; *libname dilssd '/home/ackmoto/LSAYSSD'; *libname tmp '/tmp'; /*DATA*/ /*hypothetical data*/ Data SH;/*students about teachers*/ Input LSAYID SCHF92 TCHID STEXTCUR STTALKS STTALKP KTCHID; cards; 100001 200 1 0 0 0 200001 100001 200 2 0 0 0 200002 100001 200 3 1 1 1 200003 100002 200 1 1 1 1 200001 100002 200 2 1 1 1 200002 100002 200 3 1 1 1 200003 100003 200 1 1 1 1 200001 100003 200 2 1 1 1 200002 100003 200 3 1 1 1 200003 ; RUN; Data TH;/*teachers about students*/ Input KTCHID SCHF92 STUID TSEXTCUR TSTALKS TSTALKP LSAYID; cards; 200001 200 1 1 3 3 200001 200002 200 1 1 3 3 200001 200003 200 1 1 3 3 200001 200001 200 2 1 3 3 200002 200002 200 2 1 3 3 200002 200003 200 2 1 3 3 200002 200001 200 3 1 3 3 200003 200002 200 3 1 3 3 200003 200003 200 3 1 3 3 200003 ; run; Data TTH;/*teachers about teacheres*/ Input KTCHID SCHF92 TCHID TTTALK; cards; 200001 200 200001 -9 200001 200 200002 1 200001 200 200003 2 200002 200 200001 3 200002 200 200002 -9 200002 200 200003 1 200003 200 200001 2 200003 200 200002 3 200003 200 200003 -9 ; run; DATA teacher; input schlid senseiid appl ashw awar buss care cohw cove disn disp empc fact furt grou indi intr lect mach maga mate rehw reve rout seat solv supp tv test NUM sciTEA mathTEA; cards; 200 200001 1 1 1 1 1 . 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 0 200 200002 3 3 3 3 3 3 3 . 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 1 0 200 200003 3 3 3 3 3 3 3 3 3 . 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 0 ; run; proc sort data=teacher;by /*schlid*/ senseiid; /*GET TEACHER DATA*/ data botht;set here.botht; proc sort;by /*schlid*/ senseiid; run; data norm;set here.norm; schlid=schoolid;proc sort;by /*schlid*/ senseiid;run; /*norm data contains gender, subject information as well as mission sprit variables*/ data mission;set here.mission; keep senseiid mission; senseiid=name+0; proc sort;by senseiid; data teacher;merge teacher botht norm mission;by /*schlid*/ senseiid; /*merge this with real teacher data*/ junban=_N_; if senseiid < 1000000; proc sort; by schlid senseiid;run; *proc print data=here.botht; *where schlid =201; *run; *proc print; *where junban > 500; *var senseiid schlid mission dobest; *run; data tth;set tth;if tttalk =-9 then tttalk=.; data tchques;set dil2.tchques TH; if lsayid ne .;/*anomaly, in rare occasions, lsayid is missing*/ /*fix anomaly of school 247. There are teachers who are not in student questionaire*/ /*these are temporary fix. Think of better way of doing this since in this way we lose information*/ if schf92= 247 then do; if ktchid > 247036 then DROP=1; if tchid > 247036 then DROP=1; end; if drop ne 1; data stuques;set dil2.stuques SH; if lsayid ne .; data tchtchq; set dil2.tchtchq tth; /*fix anomaly of school 247. There are teachers who are not in student questionaire*/ if schf92= 247 then do; if ktchid > 247036 then DROP=1; if tchid > 247036 then DROP=1; end; if DROP ne 1; proc sort;by ktchid tchid;run; /*fix anomaly of schoolf 303*/ Data schl303; Input ktchid schf92 tchid tttalk; Cards; 303001 303 303010 . 303002 303 303010 . 303004 303 303010 . 303009 303 303010 . 303010 303 303010 . ; RUN; proc sort;by ktchid tchid;run; data tchtchq;merge tchtchq schl303; by ktchid tchid; ***************************; *TEACHER to STUDENT matrix; ***************************; %macro gakko (bango=); data teastu; set tchques; keep ktchid lsayid schf92 stuid TSclub TSstudy TSperso flagTS; if schf92=&bango; TSclub=tsextcur; TSstudy=tstalks; TSperso=tstalkp; flagTS=1; /*making correct LSAY ID that has 100 instead of 200 at the head: network info of students got lsayid whose school digits were not exactly identical with original LSAY ID. FIXED this*/ gakko=schf92; if schf92 < 300 then gakko =schf92-100; lsayid=(gakko*1000)+stuid; proc sort;by lsayid ktchid;run; ***************************; *STUDENT MATRIX, student choosing teachers; ***************************; data stutea;set stuques; keep lsayid ktchid schf92 STclub STstudy STperso flagST tchid; if schf92=&bango; STclub=stextcur; STstudy=sttalks; STperso=sttalkp; flagST=1; proc sort;by lsayid ktchid;run; ********; *MERGE THE TWO ********; data STU; merge teastu stutea;by lsayid ktchid; /*creating reciprocal tie by combining info from student and teachers. I call new variables by simple names, club study and perso*/ /*First, make non-zero values of student data to zero*/ array kore STclub STstudy STperso; do over kore; if kore < 0 then kore=0 ; end; /*second, do the similar to teacher data*/ array are TSclub TSstudy TSperso; do over are; if are < 2 then are=0 ; if are =2 or are=3 then are=1; end; NETflag=1; /*SO NOW THE TALK IS EITHER ZERO OR ONE*/ /*I did this because teacher-student choice is 1 or 0. This wastes studnt information because it was originally asked by 0, 1,2,3*/ /*finally create scales where reciprocity of ties between teachers and students are considered*/ persoMAX=MAX(of TSperso STperso); persoAVE=MEAN(of TSperso STperso); studyMAX=MAX(of TSstudy STstudy); studyAVE=MEAN(of TSstudy STstudy); clubMAX=MAX(of TSclub STclub); clubAVE=MEAN(of TSclub STclub); proc sort; by ktchid;run; /*28% teacher name that appear in student questionaire do not appear in teacher-teacher network survey So must eliminate some teachers from consideration*/ data base;set tchtchq; keep tchid; proc sort data=base out=base nodupkey;by tchid;run; data base;set base;keep ktchid dataflag; ktchid=tchid; DATAFLAG=1; proc sort;by ktchid;run; data seito;merge STU base;by ktchid; *keep schf92 lsayid tchid ktchid study perso club bflag; if schf92=&bango; if dataflag=1; *if schf92 < 400; bflag=1; proc sort;by schf92 lsayid;run; /*make teacher id ordinal, make TCHID2*/ data ordi;set seito;keep tchid; proc sort nodupkey;by tchid;run; data ordi;set ordi;keep ORDI tchid; ORDI=_n_; proc sort data=seito out=seito;by tchid;run; proc sort data=ordi out=ordi;by tchid;run; data SEITO;merge seito ordi;by tchid; if Bflag=1; tchid2=ORDI;/*tchid2 is a new id variable*/ drop ORDI; proc sort;by lsayid /*schf92 ktchid*/; run; /*make student id ordinal, make LSAYID2*/ data seito2;set seito;keep lsayid; proc sort nodupkey data=seito2 out=seito2;by lsayid;run; data seito2;set seito2;keep lsayid lsayid2; lsayid2=_n_; proc sort; by lsayid;run; data SEITO; merge SEITO SEITO2; schlid=schf92; by lsayid; if Bflag=1;/*just cautious, this may be unnecessary*/ proc sort;by lsayid ktchid;run; *proc print data=SEITO; *proc contents data=SEITO; *****************************; *After I moved to Tampa, I added this; *Teacher information; *merging SEITO and TEACHER NORMATIVE DATA; *if possible weight the teacher infomation based on strength of TEACHER-STUDENT reciprocity; /*first sort teacher data by ktchid*/ data teacher2;set teacher; if schlid=&bango; ktchid=senseiid; proc sort;by ktchid;run; *proc print data=teacher; *run; /*second sort SEITO data by ktchid*/ data SEITT;set SEITO; if schf92=&bango; if &zzzzz > 0; flag2=1; proc sort data=SEITT out=SEITODA;by ktchid;run; /*then merge it with SEITO which is already sorted by ktchid*/ data NORM;merge SEITODA teacher2;by ktchid; if flag2=1; /*then sort by lsayid*/ proc sort data=NORM out=NORM;by lsayid;run; *proc print data=NORM; proc means data=NORM noprint mean; by lsayid;weight &zzzzz; var &chara1; output out=norm2 mean=; run; *proc print data=NORM;run; *proc print data=norm2; *run; /*I want to do a check on missing values proc means data=NORM noprint N;by lsayid;weight &zzzzz; var &chara1;output out=ARU N=; proc means data=NORM noprint NMISS;by lsayid;weight &zzzzz; var &chara1;output out=NAI NMISS=; proc print data=aru;run; proc print data=nai;run;*/ *****************************; ***************************; *TEACHER MATRIX, teachers choosing teachers; ***************************; data base;set tchtchq; if schf92=&bango; data tea;set base;keep tchid ; proc sort;by tchid;run; proc sort nodupkey data=tea out=newjun;by tchid;run; data IDalter;set newjun;keep tchid jun; jun=_n_; proc sort;by tchid;run; data IDego;set IDalter;keep ktchid jun; ktchid=tchid; proc sort;by ktchid;run; data sensei;set base; FLAG=1; proc sort;by tchid;run; /*first merge for alters*/ data abc1;merge sensei IDalter;by tchid; if FLAG=1; tchid2=jun; drop jun; proc sort;by ktchid;run; proc sort data=abc1 out=abc1;by ktchid;run; data abc1;merge abc1 idego;by ktchid; if FLAG=1; ktchid2=jun; *teachid=ktchid-1000*schf92; *alter=tchid-1000*schf92; schoolid=schf92; if tttalk < 0 then tttalk = 0; *proc print data=abc1; *run; proc iml; /*getting teacher normative orientation*/ *edit teacher; *read all var {&chara1} into teach; *Tteach=T(teach);/*transpose*/ *print teach tteach; /*teach contains practice variable*/ edit abc1;read all var {ktchid2} into rawW; edit abc1;read all var {tchid2} into columnW; edit abc1;read all var {tttalk} into valueW; close abc1; *print raww columnW valueW; *matx=j(rawW[<>],columnW[<>],.); matx=j(columnW[<>],columnW[<>],.);/* this fixed an anomaly problem: the one that occurs when the last teacher was missing as kthcid*/ N=rawW[<>]; do i=1 to nrow(rawW); matx[rawW[i],columnW[i]]=valueW[i]; end; *print rawW columnW N matx; /*replacing missing with 0*/ /* proc iml; x={ 1 . 3, 3 1 .}; print x; x=choose(x=., 0, x); print x; quit;*/ matx=choose(matx=.,0,matx); /*use receprocal information of MATX, teacher matrix missing cases were replaced with 0 earlier */ Z1=T(MATX);/*transpose T-T matrix */ TMATX=T(MATX); MATX2=TMATX<>MATX; /*whichever is larger, spoken to or speak to, is taken as freq*/ *print matx2; *create SENSEI from matx; *append from matx; /* do row=1 to nrow(matx); to_who=loc(matx[row,]); print row to_who; between=matx[to_who,to_who]; print between; end;*/ /*below I am replacing missig cases with 0 data sensei; set sensei; array subete _all_; do over subete; if subete=. then subete=0; end;*/ *****************************************; *MANIPULATE BOTH MATRIX, SEITO and SENSEI; *****************************************; edit seito; read all var {lsayid2} into LSAYID2; SAISHO=min(LSAYID2); SAIDAI=max(LSAYID2); *print saisho saidai; *DO LOOP BEGIN; DO i=saisho to saidai; read all var {&ZZZZZ} where (lsayid2=i) into X; /*this is to eventually get a number of mentors*/ read all var {&ZZZZZ} where (lsayid2=i & &ZZZZZ>0) into mentorV; /*keep only relevent raws and colums (i.e., only take student's mentors*/ /*Y1 and Y2 are instrumental matrix to derive from mentor vector*/ /*Y1 is a column vector*/ /*FIX ANOMALY: some X are shorter than the rest perhaps because of data entry mistake e.g., LSAYID 135163*/ ANOMY=nrow(X); TEST=ncol(MATX); if TEST - ANOMY > 0 then X=j(TEST,1,.); Y1=repeat(X,1,ncol(MATX)); /*make a raw vector off Y1, =X2*/ X2=T(X); Y2=repeat(X2,ncol(MATX),1); *print Y1 Y2; NEWMATX=MATX2#Y1#Y2; *print NEWMATX; ALLTIES=(NEWMATX[+,+]); /*Again fix anomaly*/ if TEST - ANOMY > 0 then ALLTIES=.; /*choosing BUNBO*/ /*BUNBO as a all possible sum of conversation*/ bunbo1=((ncol(MATX)##2)-ncol(MATX))*3; /*1 is a maxium talk in each cell*/ /*BUNBO as all possibel ties AMONG mentors*/ bunbo2=((nrow(mentorV)##2)-nrow(mentorV))*3; *print mentorV; /*mentorV is a matrix which contains only mentors*/ /*BUNBO as all conversation that mentors do with anyone */ bunbo3=(MATX2[+,+]); /*make normal density measure, not jus tmentor ship */ DENDEN=(MATX[+,+])/bunbo1; densA=ALLTIES/bunbo1; densB=ALLTIES/bunbo2; densB=choose(DENSB=., 0, DENSB); /*Again fix anomaly*/ if TEST - ANOMY > 0 then densB=.; densC=ALLTIES/bunbo3; Nmentor1=nrow(mentorV); Nmentor2=Nmentor1/ncol(MATX); DENSITY=densA || densB || densC || Nmentor1 || Nmentor2 || denden; FINAL=FINAL//DENSITY; *FINALB=FINALB//DENSB; *FINALC=FINALC//DENSC; *DO LOOP END HERE; END; close seito; /*finally I want to attach student id right next to density measures*/ /*seito2 is an instrumental vector where there are lsayid1 and lsayid2 with no dupkey*/ edit seito2; read all var {lsayid lsayid2} into ID; *print ID FINAL; /*making data for each school*/ FINAL2=ID || FINAL; colum={lsayid lsayid2 &newname.DEN1 &newname.DEN2 &newname.DEN3 N&newname.1 N&newname.2 CDENDEN}; create D&bango from FINAL2 [colname=colum]; append from FINAL2; run; /*flaggin*/ proc sort data=D&bango;by lsayid;run; data D&bango;set D&bango; ffff=1; data D&bango;merge D&bango norm2;by lsayid; if ffff=1; school=&bango; *proc means;title "&bango"; *var &newname.den3 N&newname.1 &chara1; *proc print; *run; proc sort;by school lsayid;run; %mend gakko; *%gakko (bango=200); %gakko (bango=201); %gakko (bango=202); %gakko (bango=203); %gakko (bango=204); %gakko (bango=205); %gakko (bango=206); %gakko (bango=208); %gakko (bango=209); %gakko (bango=210); %gakko (bango=211); %gakko (bango=212); %gakko (bango=214); %gakko (bango=215); %gakko (bango=216); %gakko (bango=217); %gakko (bango=218); %gakko (bango=219); %gakko (bango=220); %gakko (bango=221); %gakko (bango=222); %gakko (bango=223); %gakko (bango=224); %gakko (bango=226); %gakko (bango=227); %gakko (bango=228); %gakko (bango=229); %gakko (bango=230); %gakko (bango=231); %gakko (bango=232); %gakko (bango=233); %gakko (bango=234); %gakko (bango=235); %gakko (bango=236); %gakko (bango=237); %gakko (bango=238); %gakko (bango=239); %gakko (bango=240); %gakko (bango=241); %gakko (bango=242); %gakko (bango=243); %gakko (bango=244); %gakko (bango=245); %gakko (bango=246); %gakko (bango=247); %gakko (bango=301); %gakko (bango=302); *%gakko (bango=303); %gakko (bango=304); %gakko (bango=305); %gakko (bango=307); %gakko (bango=308); %gakko (bango=309); data here.&newname.dens; set /*D200*/ D201 D202 D203 D204 D205 D206 D208 D209 D210 D211 D212 D214 D215 D216 D217 D218 D219 D220 D221 D222 D223 D224 D226 D227 D228 D229 D230 D231 D232 D233 D234 D235 D236 D237 D238 D239 D240 D241 D242 D243 D244 D245 D246 D247 D301 D302 /*D303 */ D304 D305 D307 D308 D309 ; by school lsayid; proc means; title1 "Description of Mentorshp Network: form and content"; title2 "Mentorship Density, N of mentors, and Some selected practice"; var &newname.den2 N&newname.1 lect cove test mission; run;