************************************************************** * * * prison.do * * * * PURPOSE: this will read the data and perform 2x2 analysis * * * ************************************************************** * * NOTE: to read "string" or character variables from a file * we need to tell STATA that the specific variable * is character. Below the text "str8" that preceeds * the variable name "hivS" is used to indicate that this * variable is string variable with at most 8 characters. * infile str8 hivS str8 ivduS using u:\DEPT\513\WK1\prison.dat * * look at the character variables * tabulate hivS ivduS * * recode character into numeric * encode hivS, generate(hiv) * * NOTE: the command "encode" will take the character * variable and convert it to integers (1,2...) * based on alphabetic order. Thus, "negative" * will be coded as 1 and "positive" as 2. * We then recode this as 0 and 1. recode hiv 1=0 2=1 label define hlabs 0 "hiv-" 1 "hiv+" label values hiv hlabs * * make sure that recoding has worked! * tabulate hivS hiv * * Now recode the ivduS variable... * encode ivduS, generate(ivdu) recode ivdu 1=0 2=1 label define dlabs 0 "IVDU-no" 1 "IVDU-yes" label values ivdu dlabs tabulate ivduS ivdu * * Now you are set to use cs, cc, etc. *