multiple indicator cluster surveys data processing workshop built-in and user-defined functions mics...

38
Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User- Defined Functions MICS Data Processing Workshop

Upload: berenice-barnett

Post on 18-Jan-2016

221 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

Multiple Indicator Cluster SurveysData Processing Workshop

Built-In and User-Defined Functions

MICS Data Processing Workshop

Page 2: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

Built-In Functions

• CSPro has a wide range of built-in functions• They are not accessible for modification• Most built-in functions are well-documented in

the help system– You can see a list of these functions by searching on

“Alphabetical List of Statements and Functions” within the help system’s index tab

– We'll discuss some of the other functions which are not documented

Page 3: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

Century Month Code (CMC)

Makes date calculations easier to handle• January 1900 = CMC 1• December 1900 = CMC 12• January 1901 = CMC 13• April 2000 = CMC 1204• April 2001 = CMC 1216

• CMC = (Year-1900)*12 + Month

Page 4: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The cmcode Function

Purpose: calculate the CMC of a month/yearSyntax: cmcode(month,year)Returns:

– if month and year valid: CMC of the month/year provided

– if month or year is invalid: 9999(invalid means month or year is equal to DK, missing)

Page 5: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The setlb Function

Purpose: calculate the lower CMC bound for an event

Syntax: setlb(month,year,minimum)Returns:

– if month and year valid: CMC of month/year

– if month invalid: CMC of 1/year– if year invalid: minimum

Page 6: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The setub Function

Purpose: calculate the upper CMC bound for an event

Syntax: setub(month,year,maximum)Returns:

– if month and year valid: CMC of month/year– if month invalid: CMC of 12/year– if year invalid: maximum

Page 7: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

Example of setlb and setub

Suppose:WB1M = 98;WB1Y = 1962;

Using setlb and setub, set local variables dobLB & dobUB (DOB lower/upper bound) as follows:

dobLB = setlb(WB1M,WB1Y,0); 745dobUB = setub(WB1M,WB1Y,9999); 756

Page 8: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The adjlba FunctionPurpose: adjust lower CMC bound for an event using a

person’s age; i.e., it calculates a minimum date of birthSyntax: adjlba(lcmc,ucmc,di,di,age)Arguments:

– lcmc is the lower CMC bound of an event– ucmc is the upper CMC bound of event– di is the CMC date of interview

• Let’s denote the result as rlb (resulting lower bound)

Page 9: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The adjlba FunctionCalculates:

rlb = di – age*12 – 11we subtract 11 (months), because we assume the person just had their birthday and is therefore at the “bottom-end” of their age, with 11 more months to go before having another birthday

Returns:• if rlb in lcmc:ucmc rlb• if rlb < lcmc lcmc• if rlb > ucmc -1

Example:woman born 98/1962; her age=47; date of interview = Aug 2009adjlba (745,756,1316,1316,47) 741; however, this is below the given lcmc, and so rlb will be assigned 745

Page 10: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The adjuba FunctionPurpose: adjust upper CMC bound for an event using a

person’s age; i.e., it calculates a maximum date of birthSyntax: adjuba(lcmc,ucmc,di,di,age)Arguments:

– lcmc is the lower CMC bound of event– ucmc is the upper CMC bound of event– di is the CMC date of interview

• Let’s denote the result as rub (resulting upper bound)

Page 11: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The adjuba Function Calculates:

rub = di - age*12we make no adjustments to the person’s age, as we assume they are at the “top-end” of their age, with a birthday looming later this month or in the next month

Returns:if rub in lcmc:ucmc rubif rub > ucmc ucmcif rub < lcmc -1

Example:woman born 98/1962; her age=47; date of interview = Aug 2009adjuba (745,756,1316,1316,47) 752; since this is lower than the given ucmc, rlb will be assigned 752

Page 12: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

Example of adjlba and adjuba• Suppose

– WB1M = 98, WB1Y = 1975 and WB2 = 34 yearsdobLB = setlb(WB1M,WB1Y,0); 901dobUB = setub(WB1M,WB1Y,0); 912

− DOI is 06/2009 so di = 1314• Using the lower and upper ranges in the adjxba functions

below, we find that we can narrow the range of possible cmc birth dates to 901-906rlb=adjlba(dobLB,dobUB,di,di,WB2)901rub=adjuba(dobLB,dobUB,di,di,WB2)906

Page 13: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

User-Defined Function (UDF)

• UDFs are defined in the PROC GLOBAL block• These functions do not need to be modified

(except function vdvalid), but they do need to be understood

Page 14: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

Data Checking UDFsThere are four UDFs that assist with executing arithmetic operations:valid—checks if the value is not a special value, i.e., other (96), inconsistent (97), don’t know (98), or missing (99)NAtoZero—if a question has been skipped (assigning a value of ‘not applicable’ to that question) or is missing, this function will return 0 (zero), so that the question can be used in arithmetic equationsnotEq—a value-added <> commandbadspecial—ensures that Unit/Number questions are consistent with one another

Page 15: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The valid UDF

Purpose: ensures that a variable has a valid value

Syntax: valid (xvar)Returns:

1 if value of xvar is not “special” (i.e., is not equal to notappl) and ≤ 95

0 otherwise

Page 16: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The NAtoZero UDF

Purpose: permits one to use variables that could be “not applicable” in arithmetic equations

Syntax: NAtoZero(xvar)Returns:

0 if value of xvar is not applicable value of xvar otherwise

Page 17: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The notEq UDF

Purpose: A value-added <> check. dvar is passed thru the NAtoZero function first before the <> test is made.

Syntax: notEq(xvar,dvar)Returns:

1 if xvar <> NAtoZero (dvar)0 otherwise

Page 18: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The badspecial UDF

Purpose: Ensures that the Unit response is consistent with the Number response

Syntax: badspecial(units,number)Returns:

1 if there is a problem, i.e.,if U = 9 & N <= 90 or U <> 9 & N in 90:98 or U > 1 & N = 0

0 otherwise

Page 19: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

Birth History UDFs

• There are three UDFs that concern the birth history

• ValidYr – like valid except for 4 digit years

• AfterInt – checks if a date is after the date of interview

• ndjlba – like adjlba with a slight change

Page 20: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The validyr UDF

Purpose: ensures that a year variable has a valid year value

Syntax: validyr (xvar)Returns:

1 if value of xvar is not “special” (i.e., is not equal to notappl or missing) and ≤ 9995

0 otherwise

Page 21: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The AfterInt UDF

Purpose: ensures that a date is before the date of interview

Syntax: AfterInt (vcheckm, vchecky)Returns:

1 if vchecky > year of interview (WM6Y) or, (if vchecky = year of interview (WM6Y) and vcheckm > month of interview (WM6M) )

0 otherwise

Page 22: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The ndjlba UDF

Purpose: adjusts the lower bound a pair of century month code values for a date, based on the age reported (modified version of adjlba).

Syntax: ndjlba(lcmc,ucmc,di,di,age)Returns:

Same as for adjlba, but it avoids the possibility of producing a CMC that would imply the imputation of an age that is 1 year higher (possible with adjlba).

Page 23: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

Anthropometry UDFs

• There are seven UDFs that concern anthropometry

• The first six of these will not be discussed• The seventh is named agemth• It calculates a child’s age in months

Page 24: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The agemth UDFPurpose: calculates most accurate age in months

possible (used for anthropometry)Syntax: agemth(bd,bm,by,id,im,iy)

(i.e., child’s DOB and date of interview)

Returns:– child’s age in months if child’s birth day, month,

and year are valid– child’s age in months using 15 as day if only birth

month and year are valid– 9999 if only birth year is valid

Page 25: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

Vaccination UDFs

• There are four UDFs in the data entry application that check the validity of the vaccination date: vdvalid, vdoi, vdob and vacgiven

• There are two more UDFs in the editing program that check the ordering of vaccination dates, which we’ll discuss now: vseq and vmatch

Page 26: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The vdvalid UDF

• Purpose: checks if the vaccination date is valid (look for !!! in the logic to adjust dates per your interview period)

• Syntax: vdvalid(vday,vmonth,vyear)• Returns:

0 if vaccination date is valid1 otherwise

Page 27: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The vdoi UDF

• Purpose: checks if the vaccination is not after the date of interview

• Syntax: vdoi(vday,vmonth,vyear)• Returns:

0 if vaccination date before date of interview1 otherwise

Page 28: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The vdob UDF

• Purpose: checks if the vaccination is not before the date of birth

• Syntax: vdob(vday,vmonth,vyear)• Returns:

0 if vaccination date after date of birth1 otherwise

Page 29: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The vacgiven UDF

• Purpose: checks if the vaccination is given or not

• Syntax: vacgiven (xvar)• Returns:

1 if vaccination is given0 otherwise

Page 30: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The vseq UDF (Editing Only!)

• Purpose: checks that sequential vaccinations are in the correct order (e.g., that Polio 1 is before Polio 2)

• Syntax: vseq(v1d,v1m,v1y,v2d,v2m,v2y)

• Returns:0 if vaccination 1 was given before vaccination 2

(i.e., everything is ok)1 otherwise

Page 31: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The vmatch UDF (Editing Only!)

• Purpose: check if vaccinations commonly given on the same date (e.g., Polio and DPT) were in fact given on the same date

• Syntax: vmatch(v1d,v1m,v1y,v2d,v2m,v2y)

• Returns:0 if vaccinations given on the same date1 otherwise

Page 32: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The endmess UDF

• Syntax: endmess()• Action: in add mode displays options

1 “Review Questionnaire”2 “Next Questionnaire”

• Returns:1 if data entry operator selects “Review

Questionnaire” option from menu0 otherwise

Page 33: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The alphachk UDF

• Syntax: alphachk(alphamask)• Input: acceptable values for an alphanumeric

variable– e.g., for WS7 alphamask is “ABCDEFXZ”– e.g., for IR2 alphamask is “ABCXZ”– e.g., for MN2 alphamask is “ABCFGX”

• Assigned before entry to the function: alphavar

Page 34: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The alphachk UDFActions:• check responses in alphavar are in alphamask• check responses in alphavar are in alphabetical

order• ensure if ? is in alphavar, then it is the only

response in alphavar• places each response in alphavar in the location

defined by its subitem• e.g., for WS7, “ACEF” becomes “A C EF ”

Page 35: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

Net Roster UDFs

• There are three UDFs that concern the Insecticide Treated Nets (ITN) Roster

• Clear_labels – Clears array of labels used by SetNet

• SetNet – Prepares array of possible persons sleeping under net for display

• CheckNet – Checks validity of responses for persons sleeping under nets

Page 36: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The clear_labels UDF

• Syntax: clear_labels()• Action: blanks out all entries in two arrays:

– Labels = “”– Codes = notappl

Used in preparation for setnet• Returns:

nothing

Page 37: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The setnet UDF

• Syntax: setnet(xvarname, curnet)• Action: Creates a list of household members

and their line numbers that have not already been reported as sleeping under a net.

• Returns:Nothing, butArrays Codes and Labels are set to the line numbers of the

household members not yet reported.

Page 38: Multiple Indicator Cluster Surveys Data Processing Workshop Built-In and User-Defined Functions MICS Data Processing Workshop

The checknet UDF

• Syntax: checknet(xvar, xvarname, curnet)

• Action: Checks the line number (xvar) given as sleeping under a net with the list of household members and ensures that they have not already been listed as sleeping under a net.

• Returns:Error message number if an error was found0 otherwise