Thursday, May 2, 2013

Coursera - Passion Driven Statistics Assignment 2: Frequency Tables

I'm taking another MOOC - Passion Driven Statistics!  Mostly I chose it because it the class includes free access to SAS OnDemand.  SAS training is ridunkulously expensive... the listed price for the the course SAS Programming Introduction: Basic Concepts is currently 1100, and the combined cost for the two courses they recommend as preparation for the base certification come to around $3.5K.  So why not get some training for free with Coursera?


Anyway, I'm using some data published by Pew.  The data was in SPSS format, but it's easy to import to SAS.  Here is my code & output for the second assignment:


Code
libname mydata "/courses/u_coursera.org1/i_1006328/c_5333" access=readonly;

data new; set work.VALUES_MERGE; 

/*Change labels for race and education */
LABEL RACETHN="Race and Ethnicity"
EDUC="Last Grade Completed";
/* include only those who always or nearly always vote */
IF OFTVOTE <= 2;
/* Exclude all who did not vote or voted for a 3rd party */
IF PARTY > 2; 
/* Exclude those who didn't vote for a major party candidate */
IF PRESVOTE <=2; 

/*Treat Don't Know / Refused to answer as missing data. */
IF RACETHN = 9 then RACETHN = .;
IF PARTY=9 THEN PARTY = . ;
IF EDUC=99 THEN EDUC = . ;

/* Let those who voted for the dem be 0, those who voted for repub be 1.
This will allow us to see % repub by doing an average of PRESCATEGORY*/
IF PRESVOTE = 1 then PRESCATEGORY=0;
ELSE IF PRESVOTE = 2 then PRESCATEGORY=1;


PROC SORT;  by respid;

/* create the frequency tables */
PROC FREQ; TABLES OFTVOTE RACETHN EDUC PARTY;

Output
The FREQ Procedure
How often do you vote?
oftvoteFrequencyPercentCumulative
Frequency
Cumulative
Percent
Always386655.74386655.74
Nearly always307044.266936100.00
Frequency Missing = 258
Race and Ethnicity
racethnFrequencyPercentCumulative
Frequency
Cumulative
Percent
White Non-Hispanic608485.39608485.39
Black Non-Hispanic4696.58655391.97
Hispanic3144.41686796.38
Other Non-Hispanic2583.627125100.00
Frequency Missing = 69
Last Grade Completed
educFrequencyPercentCumulative
Frequency
Cumulative
Percent
8th or less1632.271632.27
Some H.S.3294.594926.86
H.S. Grad189926.48239133.34
Tech/Trade3344.66272537.99
Some College180425.15452963.15
College +264336.857172100.00
Frequency Missing = 22
Party Identification
partyFrequencyPercentCumulative
Frequency
Cumulative
Percent
Independent652293.21652293.21
No preference3715.30689398.51
Other party1041.496997100.00
Frequency Missing = 197

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.