Friday 6 November 2009

Creating a string variable to calculate BTH participation till 2006

*Create a string variable by the name years. The variable a width of 7 characters but i ended up using just one. Then Use IF command to assign "1" to the variable in all cases where the year was less than 2006.*****

string years (A7).

if year1="2001-02" | year1="2002-03" | year1="2003-04" | year1="2004-05" | year1="2005-06" years="1".
if year2="2001-02" | year1="2002-03" | year1="2003-04" | year1="2004-05" | year1="2005-06" years="1".
if year3="2001-02" | year1="2002-03" | year1="2003-04" | year1="2004-05" | year1="2005-06" years="1".
if year4="2001-02" | year1="2002-03" | year1="2003-04" | year1="2004-05" | year1="2005-06" years="1".
if year5="2001-02" | year1="2002-03" | year1="2003-04" | year1="2004-05" | year1="2005-06" years="1".

fre years.

list Year1 Year2 Year3 Year4 Year5 TotalYears years.

**Frequency of only those cases who meet the above criteria, ie less than 2006********.

temp.
select if years="1".
fre TotalYears/sta=all.

Wednesday 16 September 2009

Really basic stats: what can we do with these variables?

Here is a quick guide for statistics that are ok to compute with kind of variable:

OK to compute.... Nominal Ordinal Interval Ratio
frequency distribution. Yes Yes Yes Yes
median and percentiles. No Yes Yes Yes
add or subtract. No No Yes Yes
mean, standard deviation, standard error of the mean. No No Yes Yes
ratio, or coefficient of variation. No No No Yes

Source: http://www.graphpad.com/faq/viewfaq.cfm?faq=1089

Thursday 9 July 2009

More on CTABLES





*This is the command for the above table.
CTABLES
/TABLE ( Q30n + Q32n + Q34n + Q36n + Q38n + Q40n + Q41n +Q42n ) [COUNT COLPCT]
/CATEGORIES VARIABLES= Q30n Q32n Q34n Q36n Q38n Q40n Q41n Q42n [1, 2, 3, 4, SUBTOTAL, OTHERNM] EMPTY=INCLUDE POSITION=AFTER.

First attempt at CTABLES

I am a big fan of SPSS TABLES, so it took me a while to accept the shift from TABLES to CTABLES. However, I dedicated my morning to get around ctable using the Table builder and then pasting the Syntax. Here is the first syntax I used:

* Custom Tables.

CTABLES
/VLABELS VARIABLES=Q1n Q5n1 Q2n1 DISPLAY=DEFAULT
/TABLE Q1n [C] > Q5n1 [C][COUNT F40.0, COLPCT.COUNT PCT40.1] BY Q2n1 [C]
/CATEGORIES VARIABLES=Q1n ORDER=A KEY=VALUE EMPTY=INCLUDE TOTAL=YES POSITION=AFTER
/CATEGORIES VARIABLES=Q5n1 [1, 2, 3, SUBTOTAL, OTHERNM] EMPTY=INCLUDE POSITION=AFTER
/CATEGORIES VARIABLES=Q2n1 [1, 2, 3, 4, 77, OTHERNM] EMPTY=INCLUDE TOTAL=YES POSITION=AFTER.

*The easiest command would be:
CTABLES /TABLE VAR1 [COLPCT] BY VAR2.


*AND ALSO with simplification the following.

CTABLES
/VLABELS VAR= Q1n Q5n1 Q2n1 DISP=DEFAULT
/TAB Q1n>Q5n1 [COUNT F5.0, COLPCT.COUNT] BY Q2n1
/CAT VAR=Q5n1 [1,2,3, SUBTOTAL] POSITION=AFTER.

* The best part about this syntax is the ability to create SubTotals for the dependent variable which I was unable to do before!

I still need to figure out some more things, including how to use multiple choice questions!

Tuesday 23 June 2009

SPLIT FILE tip

It is really easy to split file in SPSS, and we all know that.. I don't think I need to write why it is important to use this command... But when splitting, please make sure that you SORT the file with the SPLIT variable. So for example if you are sorting your data file on gender, first sort the file on gender, then turn split on, either using syntax or menu (it does not matter)!!!

Wednesday 17 June 2009

Alter type (change variable type)

alters the type of the variable and also changes the length. For example, to change numeric to string or vice versa. You can use this command for single, multiple or ALL variables in your file. Here is the command for all variables.

ALTER TYPE ALL (A=A200).

the above will convert all the numeric to string with 200 character length. But it does not allow you to create a new version of the variable (unlike RECODE OR AUTORECODE).

For a good description of converting variable type see this UCLA page:
http://www.ats.ucla.edu/stat/spss/faq/stringnum.htm

Another good page to look at this is at the following user comment in a google group:
http://groups.google.com/group/comp.soft-sys.stat.spss/browse_thread/thread/0560f3240bb41edc?pli=1

Thursday 4 June 2009

The AMAZING TABLES of SPSS

Here are some examples in SYNTAX:

****don't forget to create a variable called t which is equal to 1*********.

COMPUTE t=1.


TABLE
/ftot t 'Total'
/tab (q405a +q405b +q405c +q405d +q405e +q405f +q405g +q405h +q405i
+q405j +q405k +q405l) by place +t
/title "danger signs pregnancy"
/sta cpct ('%' (f5.1): place) count.

TABLE
/ftot t 'Total'
/tab (q406a +q406b +q406c +q406d +q406e +q406f +q406g) by place +t
/title "dduring delivery"
/sta cpct ('%' (f5.1): place) count.

TABLE
/ftot t 'Total'
/tab (q407a +q407b +q407c +q407d +q407e +q407f +q407g ) by place +t
/title "during post partum period"
/sta cpct ('%' (f5.1): place) count.


TABLE
/ftot t 'Total'
/tab (q408a +q408b +q408c +q408d +q408e +q408f +q408g +q408h +q408i
+q408j +q408k +q408l) by place +t
/title "danger signs immediately after birth of child (1 hour)"
/sta cpct ('%' (f5.1): place) count.

TABLE
/ftot t 'Total'
/tab (q409a +q409b +q409c +q409d +q409e +q409f +q409g +q409h +q409i
+q409j +q409k +q409l + q409m + q409n)by place +t
/title "danger signs immediately after birth of child (7 days)"
/sta cpct ('%' (f5.1): place) count.


TAB
/ftot t 'total'
/mrgroup anc2 q805a q805b q805c
/tab anc2 + t by district + district>place + t
/sta cpct((f5.1):district place).

System Variables

Following are the three main System Variables:

$jdate

This variable gives the current date as the number of days from October 14, 1582.

Example:
COMPUTE today = $jdate.
exe.

$sysmis
This can be used when you want to specify that a newly created variable (or some of its values) should be set to system missing.

Example:
compute miss = $sysmis.
compute miss1 = 1.
if missing(q1) or missing(q3) miss1 = $sysmis.

$casenum
You can use this variable if you want to create an id variable that is part of your data set.

Example:
compute id = $casenum.
exe.

Source: http://www.ats.ucla.edu/stat/spss/seminars/spss_syntax/default.htm

Rename Variables

Here is the syntax:

RENAME VARIABLES {(OLD varname= NEW varname) [(varname ...)]}
{(varnames=varnames) }

Example:
RENAME VARIABLES (tm6 = Field2)(tm5 = Field1)(tm3 = MS)(tm4 = Language)(tm10
= Code)(tm1 = Query)(tm11 = Query_Code)(tm9 = Referred_to)(tm2 =
Remarks)(tm7 = Source)(tm8 = Occupation)(tm12 = Card) .


Variables can also be renamed from the Variable View tab.

Delete existing Variables

To delete one or multiple variable(s) from your data file, through syntax, use the following command:

DELETE VARIABLES varlist.

This command takes effect immediately. It does not read the active dataset or execute pending transformations. See Command Order for more information.
Example

DElETE VARIABLES varX varY thisVar TO thatVar.

Real Example:

DELETE VARIABLES Field2 Field1 MS Language Code Query Query_Code Referred_to
Remarks Source Occupation.

RENAME VARIABLES (tm6 = Field2)(tm5 = Field1)(tm3 = MS)(tm4 = Language)(tm10
= Code)(tm1 = Query)(tm11 = Query_Code)(tm9 = Referred_to)(tm2 =
Remarks)(tm7 = Source)(tm8 = Occupation)(tm12 = Card).