Wednesday, 8 December 2010

More CTable commands in Syntax

% in columns and Ns is col after it.
CTABLES /TABLE NEWS [COUNT COLPCT] /SLABELS POSITION=ROW VISIBLE=NO.


Or the same thing but the Ns in rows instead of a separate column.

CTABLES /TABLE NEWS [COUNT COLPCT].

CTABLES /TABLE (CONFINAN + CONBUS + CONBUS + CONEDUC + CONPRESS + CONMEDIC)[COUNT ROWPCT] /CLABELS ROWLABELS=OPPOSITE.

CTABLES /TABLE $MLTNEWS [COUNT COLPCT] BY SEX /SLABELS VISIBLE=NO /CATEGORIES VARIABLES=SEX TOTAL=YES.

CTABLES /TABLE POLVIEWS [COLPCT] BY AGECAT.


CTABLES /TABLE (CONFINAN + CONEDUC + CONBUS + CONMEDIC + CONPRESS + CONTV ) /SLABELS VISIBLE=NO /CLABELS ROWLABELS=OPPOSITE

OR

CTABLES /TABLE (CONFINAN + CONEDUC + CONBUS + CONMEDIC + CONPRESS + CONTV )

To add "Totals"

CTABLES /TABLE AGECAT
/CATEGORIES VARIABLES=AGECAT TOTAL=YES LABEL='Total Respondents'.
/TABLE SEX [COUNT] + HAPPY [COUNT, COLPCT] /TABLE (SEX + HAPPY [COLPCT])[COUNT]

Tuesday, 7 December 2010

Nesting in CTABLE and sorted results

example 1:
CTABLES /TABLE SEX > HAPMAR [COLPCT] BY CHILDCAT.

example 2:
CTABLES /TABLE SEX > HAPMAR BY CHILDCAT.
OR
CTABLES /TABLE (HAPPY + HAPMAR) > SEX.

choose one of the above depending on how you want the variable SEX
to be displayed the first example brings it out as the outer most variable,
while the 2nd one puts it as the inner most.


The following will give sorted result (Descending) based on
the variable CAR1 by age group
of respondent:

CTABLES
/TABLE CAR1 BY AGECAT
/CATEGORIES VARIABLES=AGECAT TOTAL=YES
/CATEGORIES VARIABLES=CAR1 ORDER=D KEY=COUNT.


(Source SPSS help file)

*In addition to the above, I want to add column percents
and Ns to the tables!!

Saturday, 27 November 2010

RECODE in STATA

recode var names (1 2 = 1 low)  ///
(3 = 2 medium) ///
(4 5 = 3 high) ///
(nonmissing = 9 "something else") ///
(missing = .) ///
, gen(Rx Ry) label(Cat3)

Use mvencode and mvdecode to deal with missing values.
For example to convert 99 into sysmis
in the variable mstatus,

mvdecode mstatus, mv(99)

For the opposite effect,
mvencode mstatus, mv(99)

Wednesday, 24 November 2010

Computing Age from DOB in SPSS

There are million ways to do this. but here is what worked for me. You will need your date of birth variable to have month, day and year.

COMPUTE age_year = (DATE.MDY(11,01,2010) - BirthDate) / (60*60*24*365.25) .

COMPUTE age=RND(age_year).
FORMATS age (F3.0).
*fre age.

NOTE: This will create an AGE variable, as of now, not the age of respondent at the time of survey. To do that you would need survey date.

Tuesday, 23 November 2010

String to Numeric in SPSS

STRING m1 (A10).

execute.

compute m1 = substr(query_co,1,1).

execute.

list m1.