Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 1. Your libname is the same as below.
- Only use the options statement to reset the starting page number of print out */
- *libname nsfhdata 'c:\statpacks\sas\data\nsfhdata';
- libname mydata "/courses/u_utoronto.ca1/i_277150/c_3291" access=readonly;
- options pageno=1;
- title 'Assignment one test program';
- /* 2. reading in the data and writing a temporary data set */
- data temp;
- set mydata.nsfh2r(keep=MUBINCR MUCOMPED MT210J MN11 MP1 MA8 MA7 MUFINW93);
- /*MUBINC: Best income
- MUCOMPED: Best education
- MT210J: Sense of control
- MN11: Religion
- MP1: Hours worked last week
- MA8: Age
- MA7: Sex
- MUFINW93: Weight variable
- */
- /* 3. Data Step statements to manipulate, recode, and create new variables */
- /* Clean up variables with convenient names*/
- income = MUBINCR;
- education = MUCOMPED;
- control = MT210j;
- religion = MN11;
- hours = MP1;
- age = MA8;
- sex = MA7;
- weight = MUFINW93;
- /* Impute for missing data of each variable */
- if income > 999990 then income=.;
- if education > 20 then education=.;
- if control < 1 then control=.;
- if control > 5 then control=.;
- /* If we decide to use religion, assign groups of categories here */
- if hours > 94 then hours=.;
- if 101 < age then age=.;
- if age < 18 then age=.;
- if 2 < sex then sex=.;
- if sex < 1 then sex=.;
- /* End of imputation */
- /* Test output of frequency
- proc freq data=temp;
- tables income education control hours age sex;
- run;
- */
- /* Turn sex into a dummy variable that is binary on female */
- female = sex-1;
- /* Turn control into dummy variables based on response */
- if control = 1 then verylowcontrol=1; else verylowcontrol=0;
- if control = 2 then lowcontrol=1; else lowcontrol=0;
- if control = 4 then highcontrol=1; else highcontrol=0;
- if control = 5 then veryhighcontrol=1; else veryhighcontrol=0;
- /* 3.6 Interactions */
- eduxcontrol = education * control;
- eduxverylowc = education * verylowcontrol;
- eduxlowc = education * lowcontrol;
- eduxhighc = education * highcontrol;
- eduxveryhighc = education * veryhighcontrol;
- agexcontrol = age * control;
- agexverylowc = age * verylowcontrol;
- agexlowc = age * lowcontrol;
- agexhighc = age * highcontrol;
- agexveryhighc = age * veryhighcontrol;
- /* 3.7 Specifically name variables to keep in the temp data set */
- keep income age female education control hours religion weight eduxcontrol
- verylowcontrol lowcontrol highcontrol veryhighcontrol eduxverylowc
- eduxlowc eduxhighc eduxveryhighc agexcontrol agexverylowc agexlowc agexhighc agexveryhighc;
- /* 4. In case you want to standardize any variables before analysis */
- proc standard data=temp out=temp2 mean=0 std=1;
- var income;
- weight weight;
- /* Run some test correlations */
- proc reg data=temp2 simple corr;
- /* Question 1, a) */
- /* Done with base variable */
- model income = education control /stb vif;
- model income = education control eduxcontrol /stb vif;
- /* Question 1, b) */
- model income = education control eduxcontrol hours age /stb vif;
- /* Question 1, C) */
- /* Done with dummy variables */
- model income = education verylowcontrol lowcontrol highcontrol veryhighcontrol /stb vif;
- model income = education verylowcontrol lowcontrol highcontrol veryhighcontrol
- eduxverylowc eduxlowc eduxhighc eduxveryhighc /stb vif;
- /* Trying again with age */
- /* Question 1, a) */
- /* Done with base variable */
- model income = age control /stb vif;
- model income = age control agexcontrol /stb vif;
- /* Question 1, b) */
- model income = age control agexcontrol hours education /stb vif;
- /* Question 1, C) */
- /* Done with dummy variables */
- model income = age verylowcontrol lowcontrol highcontrol veryhighcontrol /stb vif;
- model income = age verylowcontrol lowcontrol highcontrol veryhighcontrol
- agexverylowc agexlowc agexhighc agexveryhighc /stb vif;
- run;
Add Comment
Please, Sign In to add comment