/* this program creaets a simple peer influence effect as an example. */ libname in1xpt xport 'c:\jwm\conferences\columbia\workshop\sdatcln.xpt'; libname in1 'c:\jwm\conferences\columbia\workshop\'; /* bring in the base school data */ data sdat; set in1xpt.sdatcln; run; /* load the network and create the measures */ proc iml; reset storage = in1.netstore; load amatis amatis_id; use work.sdat; read all var{s48} into tryhard; read all var{s64} into fights; /* to get a peer influence vector, you want to weight the value of each person by the adjacency. This is a simple matrix multiplication */ /* because IML doesn't play well w. missing values, we want to do some counts first to correct for that */ thdat=choose(tryhard=.,0,1); /* flags non-missing tryhard data */ fgdat=choose(fights=.,0,1); /* flags non-missing fight data */ tryhard=choose(tryhard=.,0,tryhard); /* means that ego's non-responding alter's don't count */ fights=choose(fights=.,0,fights); /* lots of ways to get the peer influence measure. Here I use matrix mult and then divide by number w. non-missing data. We could also simply create a weight by out-degree and then row-normalize the adj. matrix */ symnet=(amatis+amatis`); /* will equal 1 if i-->j or j-->i, 2 if i<-->j */ peertry=symnet*tryhard; /* sum of edge value times data value */ ptrydat=(symnet>0)*thdat; /* count of ego's alters w. non-missing data */ th_pmean=peertry/ptrydat; peerfgt=symnet*fights; pfgtdat=(symnet>0)*fgdat; fgt_pmean=peerfgt/pfgtdat; totdeg=(symnet>0)[,+]; outd=amatis_id||th_pmean||fgt_pmean||totdeg; create work.peermeans from outd [colname={nid tryhard_pm fights_pm totdeg}]; append from outd; quit; data sdat; merge sdat peermeans; by nid; run; proc reg data=sdat; model s48 = female white s3 tryhard_pm; run; quit; proc reg data=sdat; model s64 = female white s3 fights_pm; run; quit; proc genmod data=sdat; model s64 = female white s3 fights_pm / dist = nor link = id; run; proc genmod data=sdat; model s48 = female white s3 tryhard_pm / dist = nor link = id; run; /* we know the assumptions of the model are violated, so let's try a QAP model on the dyad, which is more conservative */