Guest User

Untitled

a guest
Jun 8th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SAS 3.81 KB | None | 0 0
  1.  
  2. /* 1. Your libname is the same as below.
  3.    Only use the options statement to reset the starting page number of print out */
  4.  
  5. *libname nsfhdata 'c:\statpacks\sas\data\nsfhdata';
  6. libname mydata "/courses/u_utoronto.ca1/i_277150/c_3291" access=readonly;
  7. options pageno=1;
  8. title 'Assignment one test program';
  9.  
  10. /* 2. reading in the data and writing a temporary data set */
  11.  
  12. data temp;
  13.  
  14. set mydata.nsfh2r(keep=MUBINCR MUCOMPED MT210J MN11 MP1 MA8 MA7 MUFINW93);
  15. /*MUBINC:       Best income
  16.   MUCOMPED:     Best education
  17.   MT210J:       Sense of control
  18.   MN11:         Religion
  19.   MP1:          Hours worked last week
  20.   MA8:          Age
  21.   MA7:          Sex
  22.   MUFINW93:     Weight variable
  23. */
  24.  
  25. /* 3. Data Step statements to manipulate, recode, and create new variables */
  26.  
  27. /* Clean up variables with convenient names*/
  28.  
  29. income = MUBINCR;
  30. education = MUCOMPED;
  31. control = MT210j;
  32. religion = MN11;
  33. hours = MP1;
  34. age = MA8;
  35. sex = MA7;
  36. weight = MUFINW93;
  37.  
  38. /* Impute for missing data of each variable */
  39.  
  40. if income > 999990 then income=.;
  41. if education > 20 then education=.;
  42. if control < 1 then control=.;
  43. if control > 5 then control=.;
  44.  
  45. /* If we decide to use religion, assign groups of categories here */
  46.  
  47. if hours > 94 then hours=.;
  48.  
  49. if 101 < age then age=.;
  50. if age < 18 then age=.;
  51.  
  52. if 2 < sex then sex=.;
  53. if sex < 1 then sex=.;
  54.  
  55. /* End of imputation */
  56.  
  57. /* Test output of frequency
  58.  
  59. proc freq data=temp;
  60. tables income education control hours age sex;
  61. run;
  62. */
  63.  
  64. /* Turn sex into a dummy variable that is binary on female */
  65.  
  66. female = sex-1;
  67.  
  68. /* Turn control into dummy variables based on response */
  69.  
  70. if control = 1 then verylowcontrol=1; else verylowcontrol=0;
  71. if control = 2 then lowcontrol=1; else lowcontrol=0;
  72. if control = 4 then highcontrol=1; else highcontrol=0;
  73. if control = 5 then veryhighcontrol=1; else veryhighcontrol=0;
  74.  
  75. /* 3.6 Interactions */
  76.  
  77. eduxcontrol = education * control;
  78. eduxverylowc = education * verylowcontrol;
  79. eduxlowc = education * lowcontrol;
  80. eduxhighc = education * highcontrol;
  81. eduxveryhighc = education * veryhighcontrol;
  82.  
  83. agexcontrol = age * control;
  84. agexverylowc = age * verylowcontrol;
  85. agexlowc = age * lowcontrol;
  86. agexhighc = age * highcontrol;
  87. agexveryhighc = age * veryhighcontrol;
  88.  
  89. /* 3.7 Specifically name variables to keep in the temp data set */
  90.  
  91. keep income age female education control hours religion weight eduxcontrol
  92.      verylowcontrol lowcontrol highcontrol veryhighcontrol eduxverylowc
  93.      eduxlowc eduxhighc eduxveryhighc agexcontrol agexverylowc agexlowc agexhighc agexveryhighc;
  94.        
  95.  
  96. /* 4. In case you want to standardize any variables before analysis */
  97.  
  98. proc standard data=temp out=temp2 mean=0 std=1;
  99. var income;
  100. weight weight;
  101.  
  102. /* Run some test correlations */
  103.  
  104. proc reg data=temp2 simple corr;
  105.  
  106. /* Question 1, a) */
  107.  
  108. /* Done with base variable */
  109. model income = education control /stb vif;
  110. model income = education control eduxcontrol /stb vif;
  111.  
  112. /* Question 1, b) */
  113.  
  114. model income = education control eduxcontrol hours age /stb vif;
  115.  
  116. /* Question 1, C) */
  117.  
  118. /* Done with dummy variables */
  119.  
  120. model income = education verylowcontrol lowcontrol highcontrol veryhighcontrol /stb vif;
  121. model income = education verylowcontrol lowcontrol highcontrol veryhighcontrol
  122.                eduxverylowc eduxlowc eduxhighc eduxveryhighc /stb vif;
  123.  
  124. /* Trying again with age */
  125.  
  126. /* Question 1, a) */
  127.  
  128. /* Done with base variable */
  129. model income = age control /stb vif;
  130. model income = age control agexcontrol /stb vif;
  131.  
  132. /* Question 1, b) */
  133.  
  134. model income = age control agexcontrol hours education /stb vif;
  135.  
  136. /* Question 1, C) */
  137.  
  138. /* Done with dummy variables */
  139.  
  140. model income = age verylowcontrol lowcontrol highcontrol veryhighcontrol /stb vif;
  141. model income = age verylowcontrol lowcontrol highcontrol veryhighcontrol
  142.                agexverylowc agexlowc agexhighc agexveryhighc /stb vif;
  143.  
  144. run;
Add Comment
Please, Sign In to add comment