/*--------------------------------------------------- ex1_prep.sas Prepares the data files from UKDA for analysis Gillian raab january 2005 Original with random number starts as used is in Incomes project Replaced with 1s here --------------------------------------------------------------------*/ libname inc 'c:\documents and settings\gillian raab\my documents\aprojects\incomeproject' ; libname ex1 'c:\documents and settings\gillian raab\my documents\aprojects\peas\ex1datafiles\exemp1\data' ; libname xp xport 'C:\Documents and Settings\gillian raab\My Documents\aprojects\incomeproject/forex1.xpt'; * export file for Stata; proc copy out=ex1 in=xp; run; data ex1.ex1; * keep scottish data 4695 observations; set ex1.forex1; if gvtregn=12; drop gvtregn; psu=substr(put(sernum,10.0),1,5); * identify PSUs from part of the serial number; run; proc sort data=ex1.ex1; by psu; run; data ex1.ex1; * next steps anonymise PSUs; set ex1.ex1; by psu; if first.psu then newpsu=ranuni(565613); retain newpsu; drop psu; run; proc sort data=ex1.ex1; by newpsu; run; data ex1.ex1; set ex1.ex1; by newpsu; if _n_=1 then psu=0; if first.newpsu then psu=psu+1; sernum=_n_; gross2=round(gross2*(0.1*rannor(4879)+1));* add noise to weights; if hhinc<2 or hhinc=. then hhinc=50; * Tcases w <2 or missing incomes set to 50; hhinc=round(hhinc*(0.1*rannor(4879)+1));* add noise to income; retain psu; drop newpsu; attrib hhinc label= 'Gross household weekly income'; if tentype in (5,6) then tenure=1; * recode tenure to match census; else if tentype=1 then tenure=2; else if tentype=2 then tenure=3; else tenure=4; drop tentype; format ctband 1.0; run; proc sort data=ex1.forex1; by descending gvtregn hhinc; run; proc sort data=ex1.ex1; by hhinc; run; proc means data=ex1.ex1; var hhinc; run; proc freq data=ex1.ex1; *format ctband ctband. tentype tentype.;table ctband tenure/nopercent; weight gross2 ; run; proc contents data=ex1.ex1 ; run; * now make an export file to go to Stata and R with no variable labels on it (not sure why this does not work); * variable labels will be added in each of the other programs; libname xp xport 'C:\Documents and Settings\gillian raab\My Documents\aprojects\peas\ex1datafiles/data/ex1.xpt'; * export file for Stata; proc copy in=ex1 out=xp; select ex1; run;