library(Deducer) library(psych) yesno <- function (x) { if (is.na(x)) { y <- NA } else { if (x == "Yes") { y <- 1 } else { y <- 0 } y } } ##INSERT DATA PATHS TO ACCESS DATA (AS SAVE ON YOUR PERSONAL COMPUTER CHINA_DEMOGRAPHICS <- read.table("/Users/erinschneider/Desktop/IDFDataFiles/China/CHINA_DEMOGRAPHICS_SUBMITTED_SOURCE.csv",header=T,sep=",",quote="") CHINA_HUI <- read.table("/Users/erinschneider/Desktop/IDFDataFiles/China/CHINA_HUI_SUBMITTED_SOURCE.csv",header=T,sep=",",quote="") CHINA_IMPACT <- read.table("/Users/erinschneider/Desktop/IDFDataFiles/China/CHINA_IMPACT_SUBMITTED_SOURCE.csv",header=T,sep=",",quote="") CHINA_MEDS <- read.table("/Users/erinschneider/Desktop/IDFDataFiles/China/CHINA_MEDS_SUBMITTED_SOURCE.csv",header=T,sep=",",quote="") CHINA_SERVICES <- read.table("/Users/erinschneider/Desktop/IDFDataFiles/China/CHINA_SERVICES_SUBMITTED_SOURCE.csv",header=T,sep=",",quote="\"") CHINA_MEDS[CHINA_MEDS == ""] <- NA ## combine the different tables into a total data file x.1 <- merge(CHINA_DEMOGRAPHICS, CHINA_HUI, by="respondent") x.2 <- merge(CHINA_IMPACT, x.1, by="respondent") x.3 <- merge(CHINA_SERVICES, x.2, by="respondent") tot <- merge(CHINA_MEDS, x.3, by="respondent", all.y=TRUE) ## recoding yesno89 <- c("dm1", "wth1", "wth2", "wth3", "wth4", "wth5", "wth6", "wth7", "wth8", "wth9", "wth10", "wth12", "wth13", "wrk1", "wrk2", "wrk3", "wrk9", "wrk5", "wrk10", "wrk11", "wrk12", "wrk6", "wrk7", "wrk8", "wrk13","wrk16", "wrk17", "wrk18", "hv90", "td1", "td2", "td3", "td4", "td5", "td6", "td7", "td8", "td9", "td10", "td11", "td12", "td13", "tst1", "tst2", "tst3", "tst4", "tst5", "tst6", "tst7", "tst8", "hire", "paya", "fcg", "ins1", "ins21", "ins22", "ins23", "ins24", "ins25", "ins31", "ins32", "ins34", "ins35", "ins36", "smok", "smkp", "smks", "aspn", "med", "dm21", "dm22", "dm6a1a", "dm6a1b", "dm6a2", "dm6a3", "dm6a4", "dm6a5", "dm6a6", "dm6a7", "dm6a8", "dm6a9", "dm6a10", "dm6a11", "dm6a12", "dm6a13", "dm6i", "dm7a1", "dm7a2", "dm7a3", "dm7a4", "dm7a5") tot[yesno89] <- recode.variables(tot[yesno89], "1 -> 'Yes'; 2 -> 'No'; 88 -> 'Does Not Know'; 99 -> 'Refused'; 0 -> 'Did Not Respond'") yesnona <- c("hu1", "hu2", "hu3", "hu4", "hu5", "hu6", "hu7", "hu8", "hu9", "hu10", "hu11", "hu12", "hu13", "hu14", "hu15", "hu16", "hu17", "hu18", "hu19", "hu20", "hu21", "hu22", "hu23", "hu24", "hu25", "hu27", "hu28", "hu29", "hu30", "hu34", "hu36", "hu39","ncd1", "ncd2", "ncd3", "ncd4", "ncd5", "ncd6", "ncd7", "ncd88", "ncd99", "ncd10", "ncd11", "ncd12", "ncd13", "ncd14", "ncd15", "ncd16", "ncd17", "ncd18", "ncd19", "ncd20", "ncd21", "ncd22", "ir1", "ir2", "ir3", "ir5", "ir6", "ir7", "ir8","if1a", "if1b", "if1c", "if2a", "if2b", "if2c", "if3a", "if3b", "if3c", "if5a", "if5b", "if5c", "if6a", "if6b", "if6c","if8a", "if8b", "if8c", "sat21", "sat22", "sat23", "sat24", "sat25", "sat26", "sat27", "sat28", "sat29", "sat210", "sat211", "bta10", "bta1", "bta2", "bta3", "bta4", "bta6", "bta7", "bta8", "bta9", "acca", "accb1", "accb2", "accb3", "accb4", "accb5", "accb6", "accb7", "accb8", "accb9", "accb10", "accb11", "accb12", "dm7", "dm8", "dm9", "dm10", "dm11") tot[yesnona] <- recode.variables(tot[yesnona], "1 -> 'Yes'; 2 -> 'No'; 88 -> NA; 99 -> NA; 0 -> NA") tot[c("tyad", "tyew", "tyop")] <- recode.variables(tot[c("tyad", "tyew", "tyop")], "1 -> 'Public'; 2 -> 'Private (profit)'; 3 -> 'Private (non profit)'; 4 -> 'Other'; 88 -> 'Does Not Know'; 99 -> 'Refused'") tot[c("wtad", "wtew", "wtop")] <- recode.variables(tot[c("wtad", "wtew", "wtop")], "1 -> 'Traditional Chinese'; 2 -> 'Western'; 3 -> 'Both'; 4 -> 'Other'; 88 -> 'Does Not Know'; 99 -> 'Refused'") tot[c("lvad", "lvew", "lvop")] <- recode.variables(tot[c("lvad", "lvew", "lvop")], "1 -> 'Level 3'; 2 -> 'Level 2'; 3 -> 'Level 1'; 4 -> 'Community/town'; 5 -> 'Others'") hospital <- c("p1ad", "p1ew", "p1op", "p1ads", "p1ews", "p1ops", "p2ad", "p2ew", "p2op", "p2ads", "p2ews", "p2ops", "p3ad", "p3ew", "p3op", "p3ads", "p3ews", "p3ops") tot[hospital] <- recode.variables(tot[hospital], "1 -> 'Heart Disease'; 2 -> 'Stroke'; 3 -> 'Kidney Disease'; 4 -> 'Eye Disease'; 5 -> 'Leg or foot ulcer'; 6 -> 'Cancer'; 7 -> 'Lung Disease'; 8 -> 'Trauma'; 9 -> 'Diabetes'; 10 -> 'Childbirth'; 11 -> 'Digestive prob'; 66 -> 'Other'; 88 -> 'Does Not Know'; 99 -> 'Refused'") utilization <- c("ad90", "ew90", "op90", "ad12", "nicu", "niad") tot[utilization] <- recode.variables(tot[utilization], "88 -> NA; 99 -> NA") tot$incm[tot$incm > 20000] <- "20000" tot$incm[tot$incm == 88 | tot$incm == 99] <- NA treatment <- c("tsad1", "tsew1", "tsop1", "tsad2", "tsew2", "tsop2", "tsad3", "tsew3", "tsop3", "tsad4", "tsew4", "tsop4", "tsad5", "tsew5", "tsop5", "tsad6") tot[treatment] <- recode.variables(tot[treatment], "1 -> 'Blood test'; 2 -> 'Urine test'; 3 -> 'x-ray'; 4 -> 'minor surgery'; 5 -> 'major surgery'; 6 -> 'ECG'; 7 -> 'CT'; 8 -> 'Laser Tx'; 9 -> 'amputation'; 10 -> 'dialysis'; 66 -> 'other'; 88 -> 'Does Not Know'; 99 -> 'Refused'; 0 -> NA") tot[c("moad", "moew", "moop")] <- recode.variables(tot[c("moad", "moew", "moop")], "1 -> 'walk'; 2 -> 'bicycle'; 3 -> 'scooter/motor cycle'; 4 -> 'public bus/van'; 5 -> 'private car'; 6 -> 'taxi'; 7 -> 'ambulance'; 8 -> 'train'; 9 -> 'plane'; 66 -> 'other'; 88 -> 'Does Not Know'; 99 -> 'Refused'; 0 -> NA") nonhos <- c("wmty", "tmty", "thty", "phty", "chty") tot[nonhos] <- recode.variables(tot[nonhos], "1 -> 'Public'; 2 -> 'Private'; 3 -> 'Charity/NGO'") visits <- c("wm90", "tm90", "th90", "ph90", "ch90", "inet", "tmco", "wmco", "phco", "thco", "chco", "wmtc", "tmtc", "thtc", "phtc", "chtc", "wmtt", "tmtt", "thtt", "chtt", "m1i", "m2i", "m3i", "m4i", "m5i", "m6i", "m7i", "dm3a", "pay", "trad", "trew", "trop", "ad90", "hv90", "ew90", "op90", "ad12", "dm2yrs", "dm2months", "dm5", "dm43", "dm6h", "dm6") tot[visits] <- recode.variables(tot[visits], "99 -> NA; 88 -> NA") meds <- c("m1f", "m2f", "m3f", "m4f", "m5f", "m6f", "m7f", "m88f", "m99f") tot[meds] <- recode.variables(tot[meds], "0 -> 'as prescribed'; 1 -> 'side effects'; 2 -> 'cannot afford'; 3 -> 'forget'; 4 -> 'hard to get'; 5 -> 'help not available'; 6 -> 'syringe equipment problems'; 7 -> 'do not believe it works'; 8 -> 'do not need it'; 88 -> 'Does Not Know'; 99 -> 'Refused'; 0 -> NA") pharm <- c("m1g", "m2g", "m3g", "m4g", "m5g", "m6g", "m7g", "m88g", "m99g") tot[pharm] <- recode.variables(tot[pharm], "1 -> 'private pharmacy'; 2 -> 'hospital pharmacy'; 3 -> 'clinic'; 4 -> 'public or street market'; 5 -> 'relative or friend'; 99 -> NA") dmq <- c("dm3d", "dm3w", "dm3m", "dm3a", "dm41", "dm42", "dm43") tot[dmq] <- recode.variables(tot[dmq], "000 -> NA; 88 -> NA; 99 -> NA; 66 -> NA") tot$age[tot$age > 99] <- NA tot$fcgt[tot$fcgt == 99] <- NA tot$miss[tot$miss == 999 | tot$miss == 88 | tot$miss == 99] <- NA tot$pyad[tot$pyad == 777777] <- NA tot$tpyad[tot$tpyad == 777777] <- NA tot$tyew1[tot$tyew1 == 777777] <- NA tot$tyop1[tot$tyop1 == 777777] <- NA tot$pyadb[tot$pyadb == 777777 | tot$pyadb == 7777777] <- NA tot$pyewb[tot$pyewb == 777777 | tot$pyewb == 7777777] <- NA tot$pycb[tot$pycb == 777777 | tot$pycb == 7777777 | tot$pycb == 77777] <- NA tot$pyew[tot$pyew == 777777] <- NA tot$pypc[tot$pypc == 77777 | tot$pypc == 777777] <- NA tot$tcop[tot$tcop == 7777] <- NA tot$dm3b[tot$dm3b == 6666 | tot$dm3b == 8888 | tot$dm3b == 888 | tot$dm3b == 9999 | tot$dm3b == 666666 | tot$dm3b == 666 | tot$dm3b > 13000] <- NA tot$age[tot$age == 5 | tot$age == 7] <- 54.67 tot$dm5[tot$dm5 == 888 | tot$dm5 == 999 | tot$dm6 == 666] <- NA tot$dm3d[tot$dm3d == 888 | tot$dm3d == 999 | tot$dm3d == 666] <- NA tot$dm3w[tot$dm3w == 888 | tot$dm3w == 999 | tot$dm3w == 666] <- NA tot$dm3m[tot$dm3m == 888 | tot$dm3m == 999 | tot$dm3m == 666] <- NA ## recoding tot$location[tot$loc == "Country side" | tot$loc == "Town"] <- "Rural" tot$location[tot$loc == "City" | tot$loc == "County city" | tot$loc == "District city"] <- "Urban" tot$location <- factor(tot$location) tot$sc <- "China" tot$case[tot$case == 1] <- "Diabetes" tot$case[tot$case == 2] <- "No Diabetes" tot$case[tot$case == 3] <- "IGT" tot$loc <- as.character(tot$loc) tot$loc[tot$loc == 1] <- "City" tot$loc[tot$loc == 2] <- "District city" tot$loc[tot$loc == 3] <- "County city" tot$loc[tot$loc == 4] <- "Town" tot$loc[tot$loc == 5] <- "Country side" tot$loc[tot$loc == 8] <- "Refused" tot$sex[tot$sex == 1] <- "Male" tot$sex[tot$sex == 2] <- "Female" tot$mar[tot$mar == 1] <- "Single" tot$mar[tot$mar == 2] <- "Married" tot$mar[tot$mar == 3] <- "Widowed" tot$mar[tot$mar == 4] <- "Separated or Divorced" tot$mar[tot$mar == 5] <- "Cohabitating" tot$work[tot$wrk1 == "Yes" | tot$wrk2 == "Yes" | tot$wrk3 == "Yes" | tot$wrk12 == "Yes"] <- "Self Employed, Homemaker, or Student" tot$work[tot$wrk9 == "Yes" | tot$wrk5 == "Yes" | tot$wrk10 == "Yes" | tot$wrk11 == "Yes" | tot$wrk13 == "Yes"] <- "Employed and working" tot$work[tot$wrk7 == "Yes" | tot$wrk8 == "Yes"] <- "Not working for other reasons or retired" tot$work[tot$wrk6 == "Yes"] <- "Not working because of ill health" tot$srh[tot$hu41 == 1] <- "Excellent" tot$srh[tot$hu41 == 2] <- "Very good" tot$srh[tot$hu41 == 3] <- "Good" tot$srh[tot$hu41 == 4] <- "Fair" tot$srh[tot$hu41 == 5] <- "Poor" tot$srh[tot$hu41 == 99] <- NA tot$ratio <- as.character(tot$ratio) tot$ratio[tot$ratio == 1] <- "1 - 25%" tot$ratio[tot$ratio == 2] <- "26 - 50%" tot$ratio[tot$ratio == 3] <- "51 - 75%" tot$ratio[tot$ratio == 4] <- "76 - 100%" tot$sat1[tot$sat1 == 1] <- "satisfied" tot$sat1[tot$sat1 == 2] <- "not satisfied" tot$sat1[tot$sat1 == 3] <- "neutral" tot$sat1[tot$sat1 == 88] <- "does not know" tot$sat1[tot$sat1 == 99] <- "refused" tot$smkq[tot$smkq == 1] <- "Every day" tot$smkq[tot$smkq == 2] <- "Sometimes" tot$smkq[tot$smkq == 88] <- "Does Not Know" tot$smkq[tot$smkq == 99] <- "Refused" tot$dm3d1 <- as.character(tot$dm3d1) tot$dm3d1[tot$dm3d1 == 1] <- "always" tot$dm3d1[tot$dm3d1 == 2] <- "most of the time" tot$dm3d1[tot$dm3d1 == 3] <- "usually not" tot$dm3d1[tot$dm3d1 == 4] <- "never" tot$dm3d1[tot$dm3d1 == 88] <- "does not know" tot$dm3d1[tot$dm3d1 == 99] <- "Refused" tot$dm3c <- as.character(tot$dm3c) tot$dm3c[tot$dm3c == 1] <- "Private doctor or clinic" tot$dm3c[tot$dm3c == 2] <- "Public doctor or clinic" tot$dm3c[tot$dm3c == 3] <- "Private pharmacy or dispensary" tot$dm3c[tot$dm3c == 4] <- "Other" tot$dm3c[tot$dm3c == 7] <- NA tot$dm3c[tot$dm3c == 9] <- NA tot$dm6h <- as.character(tot$dm6h) tot$dm6h[tot$dm6h == 1] <- "Never" tot$dm6h[tot$dm6h == 2] <- "5 days or less" tot$dm6h[tot$dm6h == 3] <- "6 to 10 days" tot$dm6h[tot$dm6h == 4] <- "11 to 20 days" tot$dm6h[tot$dm6h == 5] <- "21 to 45 days" tot$dm6h[tot$dm6h == 6] <- "more than half the time" tot$dm6h[tot$dm6h == 7] <- "always" tot$dm6h[tot$dm6h == 88] <- "Does Not Know" tot$dm6h[tot$dm6h == 99] <- "Refused" tot$dm6i <- as.character(tot$dm6i) tot$dm6i[tot$dm6i == 1] <- "Never" tot$dm6i[tot$dm6i == 2] <- "Twice" tot$dm6i[tot$dm6i == 3] <- "Three times" tot$dm6i[tot$dm6i == 4] <- "Four times" tot$dm6i[tot$dm6i == 5] <- "Five or more" tot$dm6i[tot$dm6i == 6] <- "Always" tot$dm6i[tot$dm6i == 88] <- "Does Not Know" tot$dm6i[tot$dm6i == 99] <- "Refused" tot$niwa[tot$niwa == "75"] <- NA tot$ins4b[tot$ins4b == "0" | tot$ins4b == "00"] <- 0 tot$ins4b[tot$ins4b == "10"] <- 10 tot$ins4b[tot$ins4b == "100"] <- 100 tot$ins4b[tot$ins4b == "15" | tot$ins4b == "10-20"] <- 15 tot$ins4b[tot$ins4b == "20" | tot$ins4b == "10-30"] <- 20 tot$ins4b[tot$ins4b == "20-30" | tot$ins4b == "25"] <- 25 tot$ins4b[tot$ins4b == "30"] <- 30 tot$ins4b[tot$ins4b == "30-40"] <- 35 tot$ins4b[tot$ins4b == "33"] <- 33 tot$ins4b[tot$ins4b == "40"] <- 40 tot$ins4b[tot$ins4b == "5"] <- 5 tot$ins4b[tot$ins4b == "50"] <- 50 tot$ins4b[tot$ins4b == "55"] <- 55 tot$ins4b[tot$ins4b == "60"] <- 60 tot$ins4b[tot$ins4b == "70"] <- 70 tot$ins4b[tot$ins4b == "75"] <- 75 tot$ins4b[tot$ins4b == "80"] <- 80 tot$ins4b[tot$ins4b == "85"] <- 85 tot$ins4b[tot$ins4b == "88" | tot$ins4b == "888" | tot$ins4b == "999" | tot$ins4b == "99"] <- NA tot$ins4b[tot$ins4b == "90"] <- 90 tot$ins4b[tot$ins4b == "95"] <- 95 tot$ins4b[tot$ins4b == "65"] <- 65 ## 1. calculating the HUI ## vision tot$vision[tot$hu1 == "Yes" & tot$hu4 == "Yes"] <- 1 tot$vision[tot$hu1 == "Yes" & tot$hu4 == "No" & tot$hu5 == "Yes"] <- 2 tot$vision[tot$hu1 == "No" & tot$hu2 == "Yes" & tot$hu4 == "Yes"] <- 2 tot$vision[tot$hu1 == "No" & tot$hu2 == "Yes" & tot$hu4 == "No" & tot$hu5 == "Yes"] <- 2 tot$vision[tot$hu1 == "Yes" & tot$hu4 == "No" & tot$hu5 == "No"] <- 3 tot$vision[tot$hu1 == "No" & tot$hu2 == "Yes" & tot$hu4 == "No" & tot$hu5 == "No"] <- 3 tot$vision[tot$hu1 == "No" & tot$hu2 == "No" & tot$hu3 == "Yes" & tot$hu4 == "No" & tot$hu5 == "Yes"] <- 4 tot$vision[tot$hu1 == "No" & tot$hu2 == "No" & tot$hu3 == "Yes" & tot$hu4 == "Yes"] <- 4 tot$vision[tot$hu1 == "No" & tot$hu2 == "No" & tot$hu4 == "No" & tot$hu5 == "No" & tot$hu3 == "Yes"] <- 5 tot$vision[tot$hu1 == "No" & tot$hu2 == "No" & tot$hu3 == "No"] <- 6 ## multi attribute weights tot$v.tscore[tot$vision == 1] <- 1 tot$v.tscore[tot$vision == 2] <- 0.98 tot$v.tscore[tot$vision == 3] <- 0.89 tot$v.tscore[tot$vision == 4] <- 0.84 tot$v.tscore[tot$vision == 5] <- 0.75 tot$v.tscore[tot$vision == 6] <- 0.61 ## hearing tot$hear[tot$hu6 == "Yes"] <- 1 tot$hear[tot$hu6 == "No" & tot$hu7 == "Yes" & tot$hu9 == "Yes"] <- 2 tot$hear[tot$hu6 == "No" & tot$hu7 == "Yes" & tot$hu9 == "No" & tot$hu10 == "Yes"] <- 3 tot$hear[tot$hu6 == "No" & tot$hu7 == "Yes" & tot$hu9 == "No" & tot$hu10 == "No"] <- 3 tot$hear[tot$hu6 == "No" & tot$hu7 == "No" & tot$hu8 == "Yes" & tot$hu9 == "Yes"] <- 4 tot$hear[tot$hu6 == "No" & tot$hu7 == "No" & tot$hu8 == "Yes" & tot$hu9 == "No" & tot$hu10 == "Yes"] <- 5 tot$hear[tot$hu6 == "No" & tot$hu7 == "No" & tot$hu8 == "Yes" & tot$hu9 == "No" & tot$hu10 == "No"] <- 6 tot$hear[tot$hu6 == "No" & tot$hu7 == "No" & tot$hu8 == "No"] <- 6 ## multi attribute weights tot$h.tscore[tot$hear == 1] <- 1 tot$h.tscore[tot$hear == 2] <- 0.95 tot$h.tscore[tot$hear == 3] <- 0.89 tot$h.tscore[tot$hear == 4] <- 0.80 tot$h.tscore[tot$hear == 5] <- 0.74 tot$h.tscore[tot$hear == 6] <- 0.61 ## speech tot$speech[tot$hu11 == "Yes"] <- 1 tot$speech[tot$hu11 == "No" & tot$hu12 == "Yes" & tot$hu13 == "Yes"] <- 2 tot$speech[tot$hu11 == "No" & tot$hu12 == "Yes" & tot$hu13 == "No" & tot$hu14 == "Yes"] <- 3 tot$speech[tot$hu11 == "No" & tot$hu12 == "No" & tot$hu13 == "Yes"] <- 4 tot$speech[tot$hu11 == "No" & tot$hu12 == "No" & tot$hu13 == "No" & tot$hu14 == "Yes"] <- 4 tot$speech[tot$hu11 == "No" & tot$hu12 == "Yes" & tot$hu13 == "No" & tot$hu14 == "No" & tot$hu15 == "Yes"] <- 5 tot$speech[tot$hu11 == "No" & tot$hu12 == "Yes" & tot$hu13 == "No" & tot$hu14 == "No" & tot$hu15 == "No"] <- 5 tot$speech[tot$hu11 == "No" & tot$hu12 == "No" & tot$hu13 == "No" & tot$hu14 == "No" & tot$hu15 == "Yes"] <- 5 tot$speech[tot$hu11 == "No" & tot$hu12 == "No" & tot$hu13 == "No" & tot$hu14 == "No" & tot$hu15 == "No"] <- 5 ## multi attribute weights tot$s.tscore[tot$speech == 1] <- 1 tot$s.tscore[tot$speech == 2] <- 0.94 tot$s.tscore[tot$speech == 3] <- 0.89 tot$s.tscore[tot$speech == 4] <- 0.81 tot$s.tscore[tot$speech == 5] <- 0.68 ## mobility tot$mobil[tot$hu16 == "Yes"] <- 1 tot$mobil[tot$hu16 == "No" & tot$hu17 == "Yes"] <- 1 tot$mobil[tot$hu16 == "No" & tot$hu17 == "No" & tot$hu18 == "Yes"] <- 2 tot$mobil[tot$hu16 == "No" & tot$hu17 == "No" & tot$hu18 == "No" & tot$hu19 == "Yes" & tot$hu20 == "Yes" & tot$hu21 == "No" & tot$hu22 == "No"] <- 3 tot$mobil[tot$hu16 == "No" & tot$hu17 == "No" & tot$hu18 == "No" & tot$hu19 == "Yes" & tot$hu20 == "No" & tot$hu21 == "No" & tot$hu22 == "No"] <- 3 tot$mobil[tot$hu16 == "No" & tot$hu17 == "No" & tot$hu18 == "No" & tot$hu19 == "Yes" & tot$hu20 == "Yes" & tot$hu21 == "No" & tot$hu22 == "Yes"] <- 4 tot$mobil[tot$hu16 == "No" & tot$hu17 == "No" & tot$hu18 == "No" & tot$hu19 == "Yes" & tot$hu20 == "No" & tot$hu21 == "No" & tot$hu22 == "Yes"] <- 4 tot$mobil[tot$hu16 == "No" & tot$hu17 == "No" & tot$hu18 == "No" & tot$hu19 == "Yes" & tot$hu20 == "Yes" & tot$hu21 == "Yes" & tot$hu22 == "Yes"] <- 5 tot$mobil[tot$hu16 == "No" & tot$hu17 == "No" & tot$hu18 == "No" & tot$hu19 == "Yes" & tot$hu20 == "Yes" & tot$hu21 == "Yes" & tot$hu22 == "No"] <- 5 tot$mobil[tot$hu16 == "No" & tot$hu17 == "No" & tot$hu18 == "No" & tot$hu19 == "Yes" & tot$hu20 == "No" & tot$hu21 == "Yes" & tot$hu22 == "Yes"] <- 5 tot$mobil[tot$hu16 == "No" & tot$hu17 == "No" & tot$hu18 == "No" & tot$hu19 == "Yes" & tot$hu20 == "No" & tot$hu21 == "Yes" & tot$hu22 == "No"] <- 5 tot$mobil[tot$hu16 == "No" & tot$hu17 == "No" & tot$hu18 == "No" & tot$hu19 == "No" & tot$hu22 == "Yes"] <- 6 tot$mobil[tot$hu16 == "No" & tot$hu17 == "No" & tot$hu18 == "No" & tot$hu19 == "No" & tot$hu22 == "No"] <- 6 ## multi attribute weights tot$m.tscore[tot$mobil == 1] <- 1 tot$m.tscore[tot$mobil == 2] <- 0.93 tot$m.tscore[tot$mobil == 3] <- 0.86 tot$m.tscore[tot$mobil == 4] <- 0.73 tot$m.tscore[tot$mobil == 5] <- 0.65 tot$m.tscore[tot$mobil == 6] <- 0.58 ## hands tot$hu26[tot$hu26 == 99] <- NA tot$hands[tot$hu24 == "Yes"] <- 1 tot$hands[tot$hu24 == "No" & tot$hu25 == "No" & tot$hu27 == "No"] <- 2 tot$hands[tot$hu24 == "No" & tot$hu25 == "No" & tot$hu27 == "Yes" ] <- 3 tot$hands[tot$hu24 == "No" & tot$hu25 == "Yes" & tot$hu26 == 1 & tot$hu27 == "Yes"] <- 4 tot$hands[tot$hu24 == "No" & tot$hu25 == "Yes" & tot$hu26 == 1 & tot$hu27 == "No"] <- 4 tot$hands[tot$hu24 == "No" & tot$hu25 == "Yes" & tot$hu26 == 2 & tot$hu27 == "Yes"] <- 5 tot$hands[tot$hu24 == "No" & tot$hu25 == "Yes" & tot$hu26 == 2 & tot$hu27 == "No"] <- 5 tot$hands[tot$hu24 == "No" & tot$hu25 == "Yes" & tot$hu26 == 3 & tot$hu27 == "Yes"] <- 6 tot$hands[tot$hu24 == "No" & tot$hu25 == "Yes" & tot$hu26 == 3 & tot$hu27 == "No"] <- 6 ## multi attribute weights tot$hd.tscore[tot$hands == 1] <- 1 tot$hd.tscore[tot$hands == 2] <- 0.95 tot$hd.tscore[tot$hands == 3] <- 0.88 tot$hd.tscore[tot$hands == 4] <- 0.76 tot$hd.tscore[tot$hands == 5] <- 0.65 tot$hd.tscore[tot$hands == 6] <- 0.56 ## emotion tot$emo[tot$hu31 == 1 & tot$hu32 == 1] <- 1 tot$emo[tot$hu31 == 1 & tot$hu32 == 2] <- 2 tot$emo[tot$hu31 == 2 & tot$hu33 == 1] <- 3 tot$emo[tot$hu31 == 2 & tot$hu33 == 2] <- 4 tot$emo[tot$hu31 == 2 & tot$hu33 == 3] <- 5 ## multi attribute weights tot$e.tscore[tot$emo == 1] <- 1 tot$e.tscore[tot$emo == 2] <- 0.95 tot$e.tscore[tot$emo == 3] <- 0.85 tot$e.tscore[tot$emo == 4] <- 0.64 tot$e.tscore[tot$emo == 5] <- 0.46 ## cognition - changes in the chinese version to include "very forgetful" tot$cog[tot$hu37 == 1 & tot$hu38 == 1] <- 1 tot$cog[tot$hu37 == 1 & tot$hu38 == 2] <- 2 tot$cog[tot$hu37 == 1 & tot$hu38 == 3] <- 2 tot$cog[tot$hu37 == 1 & tot$hu38 == 4] <- 5 tot$cog[tot$hu37 == 1 & tot$hu38 == 5] <- 6 tot$cog[tot$hu37 == 2 & tot$hu38 == 1] <- 3 tot$cog[tot$hu37 == 2 & tot$hu38 == 2] <- 4 tot$cog[tot$hu37 == 2 & tot$hu38 == 3] <- 4 tot$cog[tot$hu37 == 2 & tot$hu38 == 4] <- 5 tot$cog[tot$hu37 == 2 & tot$hu38 == 5] <- 6 tot$cog[tot$hu37 == 3 & tot$hu38 == 1] <- 5 tot$cog[tot$hu37 == 3 & tot$hu38 == 2] <- 5 tot$cog[tot$hu37 == 3 & tot$hu38 == 3] <- 5 tot$cog[tot$hu37 == 3 & tot$hu38 == 4] <- 5 tot$cog[tot$hu37 == 3 & tot$hu38 == 5] <- 6 tot$cog[tot$hu37 == 4 & tot$hu38 == 1] <- 6 tot$cog[tot$hu37 == 4 & tot$hu38 == 2] <- 6 tot$cog[tot$hu37 == 4 & tot$hu38 == 3] <- 6 tot$cog[tot$hu37 == 4 & tot$hu38 == 4] <- 6 tot$cog[tot$hu37 == 4 & tot$hu38 == 5] <- 6 ## multi attribute weights tot$c.tscore[tot$cog == 1] <- 1 tot$c.tscore[tot$cog == 2] <- 0.92 tot$c.tscore[tot$cog == 3] <- 0.95 tot$c.tscore[tot$cog == 4] <- 0.83 tot$c.tscore[tot$cog == 5] <- 0.60 tot$c.tscore[tot$cog == 6] <- 0.42 ## pain tot$pain[tot$hu39 == "No"] <- 1 tot$pain[tot$hu39 == "Yes" & tot$hu40 == 1] <- 2 tot$pain[tot$hu39 == "Yes" & tot$hu40 == 2] <- 3 tot$pain[tot$hu39 == "Yes" & tot$hu40 == 3] <- 4 tot$pain[tot$hu39 == "Yes" & tot$hu40 == 4] <- 5 tot$pain[tot$hu39 == "Yes" & tot$hu40 == 5] <- 5 ## multi attribute weights tot$p.tscore[tot$pain == 1] <- 1 tot$p.tscore[tot$pain == 2] <- 0.96 tot$p.tscore[tot$pain == 3] <- 0.90 tot$p.tscore[tot$pain == 4] <- 0.77 tot$p.tscore[tot$pain == 5] <- 0.55 ## total hui score tot$hui <- (1.371*(tot$v.tscore * tot$h.tscore * tot$s.tscore * tot$m.tscore * tot$hd.tscore * tot$e.tscore * tot$c.tscore * tot$p.tscore)) - 0.371 ## by-domain scores ## vision domain tot$v.iscore[tot$vision == 1] <- 1 tot$v.iscore[tot$vision == 2] <- 0.95 tot$v.iscore[tot$vision == 3] <- 0.73 tot$v.iscore[tot$vision == 4] <- 0.59 tot$v.iscore[tot$vision == 5] <- 0.38 tot$v.iscore[tot$vision == 6] <- 0.00 ## hearing domain tot$h.iscore[tot$hear == 1] <- 1 tot$h.iscore[tot$hear == 2] <- 0.86 tot$h.iscore[tot$hear == 3] <- 0.71 tot$h.iscore[tot$hear == 4] <- 0.48 tot$h.iscore[tot$hear == 5] <- 0.32 tot$h.iscore[tot$hear == 6] <- 0.00 ## speech domain tot$s.iscore[tot$speech == 1] <- 1 tot$s.iscore[tot$speech == 2] <- 0.82 tot$s.iscore[tot$speech == 3] <- 0.67 tot$s.iscore[tot$speech == 4] <- 0.41 tot$s.iscore[tot$speech == 5] <- 0.00 ## mobility-ambulation domain tot$m.iscore[tot$mobil == 1] <- 1 tot$m.iscore[tot$mobil == 2] <- 0.83 tot$m.iscore[tot$mobil == 3] <- 0.67 tot$m.iscore[tot$mobil == 4] <- 0.36 tot$m.iscore[tot$mobil == 5] <- 0.16 tot$m.iscore[tot$mobil == 6] <- 0.00 ## hands-dexterity domain tot$hd.iscore[tot$hands == 1] <- 1 tot$hd.iscore[tot$hands == 2] <- 0.88 tot$hd.iscore[tot$hands == 3] <- 0.73 tot$hd.iscore[tot$hands == 4] <- 0.45 tot$hd.iscore[tot$hands == 5] <- 0.20 tot$hd.iscore[tot$hands == 6] <- 0.00 ## emotion domain tot$e.iscore[tot$emo == 1] <- 1 tot$e.iscore[tot$emo == 2] <- 0.91 tot$e.iscore[tot$emo == 3] <- 0.73 tot$e.iscore[tot$emo == 4] <- 0.33 tot$e.iscore[tot$emo == 5] <- 0.00 ## coginition domain tot$c.iscore[tot$cog == 1] <- 1 tot$c.iscore[tot$cog == 2] <- 0.86 tot$c.iscore[tot$cog == 3] <- 0.92 tot$c.iscore[tot$cog == 4] <- 0.70 tot$c.iscore[tot$cog == 5] <- 0.32 tot$c.iscore[tot$cog == 6] <- 0.00 ## pain domain tot$p.iscore[tot$pain == 1] <- 1 tot$p.iscore[tot$pain == 2] <- 0.92 tot$p.iscore[tot$pain == 3] <- 0.77 tot$p.iscore[tot$pain == 4] <- 0.48 tot$p.iscore[tot$pain == 5] <- 0.00 ## 2. new variables ## binomial married tot$married[tot$mar == "Married"] <- "Yes" tot$married[tot$mar == "Cohabitating" | tot$mar == "Separated or Divorced" | tot$mar == "Single" | tot$mar == "Widowed"] <- "No" ## ever smoked tot$smkp[tot$smkp == 9] <- "Refused" tot$eversmoke[tot$smok == "Yes" | tot$smkp == "Yes"] <- "Yes" tot$eversmoke[tot$smok == "No" & tot$smkp == "No"] <- "No" ## 3. Outcome variables ## health measures ## presence of DM conditions tot$cvd <- "No" tot$cvd[tot$ncd1 == "Yes" | tot$ncd2 == "Yes" | tot$ncd3 == "Yes" | tot$ncd4 == "Yes"] <- "Yes" tot$dm.ncd <- "No" tot$dm.ncd[tot$ncd1 == "Yes" | tot$ncd2 == "Yes" | tot$ncd3 == "Yes" | tot$ncd4 == "Yes" | tot$ncd11 == "Yes" | tot$ncd17 == "Yes" | tot$ncd13 == "Yes" | tot$ncd16 == "Yes" | tot$ncd14 == "Yes" | tot$ncd15 == "Yes" | tot$ncd12 == "Yes"] <- "Yes" tot$kidney[tot$ncd11 == "Yes" | tot$ncd17 == "Yes"] <- "Yes" tot$kidney[tot$ncd11 == "No" & tot$ncd17 == "No"] <- "No" tot$foot[tot$ncd14 == "Yes" | tot$ncd15 == "Yes" | tot$ncd12 == "Yes"] <- "Yes" tot$foot[tot$ncd14 == "No" & tot$ncd14 == "No" & tot$ncd12 == "No"] <- "No" tot$eye[tot$ncd13 == "Yes" | tot$ncd16 == "Yes"] <- "Yes" tot$eye[tot$ncd13 == "No" & tot$ncd16 == "No"] <- "No" tot$micro <- "No" tot$micro[tot$ncd11 == "Yes" | tot$ncd10 == "Yes" | tot$ncd12 == "Yes" | tot$ncd13 == "Yes" | tot$ncd14 == "Yes" | tot$ncd15 == "Yes" | tot$ncd16 == "Yes" | tot$ncd17 == "Yes"] <- "Yes" tot$strokemi <- "No" tot$strokemi[tot$ncd4 == "Yes" | tot$ncd4 == "Yes"] <- "Yes" tot$macro <- "No" tot$macro[tot$ncd1 == "Yes" | tot$ncd2 == "Yes" | tot$ncd3 == "Yes" | tot$ncd4 == "Yes" | tot$ncd5 == "Yes"] <- "Yes" tot$anyncd <- "No" tot$anyncd[tot$cvd == "Yes" | tot$ncd5 == "Yes" | tot$ncd6 == "Yes" | tot$ncd7 == "Yes" | tot$ncd88 == "Yes" | tot$ncd11 == "Yes" | tot$ncd18 == "Yes" | tot$ncd19 == "Yes"] <- "Yes" tot$any.cc <- "No" tot$any.cc[tot$cvd == "Yes" | tot$ncd5 == "Yes" | tot$ncd6 == "Yes" | tot$ncd7 == "Yes" | tot$ncd88 == "Yes" | tot$ncd11 == "Yes" | tot$ncd99 == "Yes" | tot$ncd10 == "Yes" | tot$ncd12 == "Yes" | tot$ncd13 == "Yes" | tot$ncd14 == "Yes" | tot$ncd15 == "Yes" | tot$ncd16 == "Yes" | tot$ncd17 == "Yes" | tot$ncd18 == "Yes" | tot$ncd19 == "Yes" | tot$ncd20 == "Yes" | tot$ncd21 == "Yes" | tot$ncd22 == "Yes"] <- "Yes" tot$any.no.cvd <- "No" tot$any.no.cvd[tot$ncd5 == "Yes" | tot$ncd6 == "Yes" | tot$ncd7 == "Yes" | tot$ncd88 == "Yes" | tot$ncd11 == "Yes" | tot$ncd99 == "Yes" | tot$ncd10 == "Yes" | tot$ncd12 == "Yes" | tot$ncd13 == "Yes" | tot$ncd14 == "Yes" | tot$ncd15 == "Yes" | tot$ncd16 == "Yes" | tot$ncd17 == "Yes" | tot$ncd18 == "Yes" | tot$ncd19 == "Yes" | tot$ncd20 == "Yes" | tot$ncd21 == "Yes" | tot$ncd22 == "Yes"] <- "Yes" tot$mental <- "No" tot$mental[tot$ncd18 == "Yes" | tot$ncd19 == "Yes"] <- "Yes" tot$anyncd.no.hyp <- "No" tot$anyncd.no.hyp[tot$cvd == "Yes" | tot$ncd6 == "Yes" | tot$ncd7 == "Yes" | tot$ncd88 == "Yes" | tot$ncd11 == "Yes" | tot$ncd99 == "Yes" | tot$ncd10 == "Yes" | tot$ncd12 == "Yes" | tot$ncd13 == "Yes" | tot$ncd14 == "Yes" | tot$ncd15 == "Yes" | tot$ncd16 == "Yes" | tot$ncd17 == "Yes" | tot$ncd18 == "Yes" | tot$ncd19 == "Yes" | tot$ncd20 == "Yes" | tot$ncd21 == "Yes" | tot$ncd22 == "Yes"] <- "Yes" tot$tb.lung <- "No" tot$tb.lung[tot$ncd7 == "Yes" | tot$ncd88 == "Yes" | tot$td1 == "Yes"] <- "Yes" ##Acute Illness tot$acute <- "No" tot$acute[tot$td1 == "Yes" | tot$td2 == "Yes" | tot$td11 == "Yes" | tot$td3 == "Yes" | tot$td12 == "Yes" | tot$td4 == "Yes" | tot$td13 == "Yes" | tot$td5 == "Yes" | tot$td7 == "Yes" | tot$td8 == "Yes" | tot$td9 == "Yes" | tot$td10 == "Yes"] <- "Yes" ## 4. utilization ## any non-hospital use tot$nonhos <- "No" tot$nonhos[tot$wm90 > 0 | tot$tm90 > 0 | tot$ph90 > 0 | tot$th90 > 0 | tot$ch90 > 0] <- "Yes" tot$nonhos[is.na(tot$wm90) & is.na(tot$tm90) & is.na(tot$ph90) & is.na(tot$th90) & is.na(tot$ch90)] <- NA ## 5. Establish site and case based on IDs tot$site <- substr(tot$respondent, 2, 3) tot$case.test <- substr(tot$respondent, 4, 4) tot$case.test[tot$case.test == 1] <- "Diabetes" tot$case.test[tot$case.test == 2] <- "No Diabetes" tot$case.test[tot$case.test == 3] <- "IGT" ## 6. clean out disparities tot <- tot[!is.na(tot$respondent),] tot <- tot[tot$case == tot$case.test,] ## exclude those who answered questions for pwd and had no Diabetes x.1 <- (tot$case == "No Diabetes" & is.na(tot$dm21) & !is.na(tot$case)) nds <- tot[x.1,] ## exclude those with IGT who answered "Yes" to insulin question x.2 <- (tot$case == "IGT" & tot$dm21 == "No" & !is.na(tot$dm21) & !is.na(tot$case)) igt1 <- tot[x.2,] x.3 <- (tot$case == "IGT" & is.na(tot$dm21) & !is.na(tot$case)) igt2 <- tot[x.3,] igt <- rbind(igt1, igt2) ## people with diabetes x.4 <- tot$case == "Diabetes" & !(is.na(tot$case)) dms <- tot[x.4,] tot <- rbind(nds, igt, dms) ## 7. file for export (.CHINA_PERSON_DATA) x <- data.frame(site=tot$site, case=tot$case, ID=tot$respondent, loc=tot$loc, m.status=tot$mar, married=tot$married, agesqd=tot$agesqd, age=tot$age, sex=tot$sex, hist.hibg=tot$dm1, work=tot$work, fam.size=tot$inet, income=tot$incm, sc=tot$sc, ever.smoke=tot$eversmoke, curr.smoke=tot$smok, smks=tot$smks, hui.total=tot$hui, vision=tot$v.iscore, hear=tot$h.iscore, speech=tot$s.iscore, mobility=tot$m.iscore, hands=tot$hd.iscore, emotion=tot$e.iscore, cognition=tot$c.iscore, pain=tot$p.iscore, nonhos=tot$nonhos, spad=tot$spad, spew=tot$spew, spop=tot$spop, hosp.90=tot$hv90, hosp.ad=tot$ad90, hosp.ew=tot$ew90, hosp.op=tot$op90, hosp.365=tot$ad12, reason.ad=tot$p1ad, reason.ew=tot$p1ew, reason.op=tot$p1op, niwa=tot$niwa, nicu=tot$nicu, daew=tot$daew, daop=tot$daop, pyad=tot$pyad, pyew=tot$pyew, pypc=tot$pypc, wm90=tot$wm90, wmco=tot$wmco, tm90=tot$tm90, tmco=tot$tmco, th90=tot$th90, phty=tot$phty, thco=tot$thco, ph90=tot$ph90, phco=tot$phco, ch90=tot$ch90, chco=tot$chco, m1i=tot$m1i, m2i=tot$m2i, m3i=tot$m3i, m4i=tot$m4i, m5i=tot$m5i, m6i=tot$m6i, m7i=tot$m7i, m88i=tot$m88i, m99i=tot$m99i, m1d=tot$m1d, m2d=tot$m2d, m3d=tot$m3d, m4d=tot$m4d, m5d=tot$m5d, m6d=tot$m6d, m7d=tot$m7d, m88d=tot$m88d, m99d=tot$m99d, m1e=tot$m1e, m2e=tot$m2e, m3e=tot$m3e, m4e=tot$m4e, m5e=tot$m5e, m6e=tot$m6e, m7e=tot$m7e, m88e=tot$m88e, m99e=tot$m99e, m1h=tot$m1h, m2h=tot$m2h, m3h=tot$m3h, m4h=tot$m4h, m5h=tot$m5h, m6h=tot$m6h, m7h=tot$m7h, m88h=tot$m88h, m99h=tot$m99h, m1f=tot$m1f, m2f=tot$m2f, m3f=tot$m3f, m4f=tot$m4f, m5f=tot$m5f, m6f=tot$m6f, m7f=tot$m7f, m88f=tot$m88f, m99f=tot$m99f, m1a=tot$m1a, m2a=tot$m2a, m3a=tot$m3a, m4a=tot$m4a, m5a=tot$m5a, m6a=tot$m6a, m7a=tot$m7a, m88a=tot$m88a, m99a=tot$m99a, m1b=tot$m1b, m2b=tot$m2b, m3b=tot$m3b, m4b=tot$m4b, m5b=tot$m5b, m6b=tot$m6b, m7b=tot$m7b, m88b=tot$m88b, m99b=tot$m99b, m1c=tot$m1c, m2c=tot$m2c, m3c=tot$m3c, m4c=tot$m4c, m5c=tot$m5c, m6c=tot$m6c, m7c=tot$m7c, m88c=tot$m88c, m99c=tot$m99c, m1g=tot$m1g, m2g=tot$m2g, m3g=tot$m3g, m4g=tot$m4g, m5g=tot$m5g, m6g=tot$m6g, m7g=tot$m7g, m88g=tot$m88g, m99g=tot$m99g, hire=tot$hire, pay=tot$pay, fcg=tot$fcg, fcgt=tot$fcgt, miss=tot$miss, wm.visit=tot$wm90, tm.visit=tot$tm90, th.visit=tot$th90, ph.visit=tot$ph90, ch.visit=tot$ch90, strokemi=tot$strokemi, cvd=tot$cvd, kidney=tot$kidney, foot=tot$foot, eye=tot$eye, any.ncd=tot$anyncd, ncd1=tot$ncd1, ncd2=tot$ncd2, ncd3=tot$ncd3, ncd4=tot$ncd4, ncd5=tot$ncd5, ncd6=tot$ncd6, ncd7=tot$ncd7, ncd88=tot$ncd88, ncd99=tot$ncd99, ncd10=tot$ncd10, ncd11=tot$ncd11, ncd12=tot$ncd12, ncd13=tot$ncd13, ncd14=tot$ncd14, ncd15=tot$ncd15, ncd16=tot$ncd16, ncd17=tot$ncd17, ncd18=tot$ncd18, ncd19=tot$ncd19, ncd20=tot$ncd20, ncd21=tot$ncd21, ncd22=tot$ncd22, macro=tot$macro, micro=tot$micro, anyncd=tot$anyncd, dm.ncd=tot$dm.ncd, any.cc=tot$any.cc, any.no.cvd=tot$any.no.cvd, mental=tot$mental, tb.lung=tot$tb.lung, anyncd.no.hyp=tot$anyncd.no.hyp, tb=tot$td1, malaria=tot$td2, flu=tot$td3, pneumonia=tot$td4, diarrhea=tot$td5, preg=tot$td6, other.inf=tot$td7, other.para=tot$td8, injury=tot$td9, cold=tot$td10, typhoid=tot$td11, other.ill=tot$td13, acute=tot$acute, urine.test=tot$tst1, blood.test=tot$tst2, finger.stick=tot$tst3, bp.test=tot$tst4, eye.test=tot$tst5, foot.test=tot$tst6, weight.test=tot$tst7, wc.test=tot$tst8, srh=tot$srh, miss.work=tot$miss, f.miss=tot$fcg, src.incm=tot$bta1, src.welfare=tot$bta2, src.donat=tot$bta3, src.family=tot$bta4, src.save=tot$bta6, src.borrow=tot$bta7, src.sell.pos=tot$bta8, src.sell.house=tot$bta9, acc.money=tot$accb1, acc.transport=tot$accb2, acc.friend=tot$accb3, acc.distance=tot$accb4, acc.wait=tot$accb5, acc.ins=tot$accb6, acc.sick=tot$accb7, acc.doc=tot$accb8, acc.trust=tot$accb9, acc.where=tot$accb10, acc.other=tot$accb12, aspn=tot$aspn, any.meds=tot$med, insulin=tot$dm21, insurance=tot$ins1, sat.service=tot$sat21, sat.skill=tot$sat22, sat.equip=tot$sat23, sat.overcare=tot$sat24, sat.charge=tot$sat25, sat.cost=tot$sat26, sat.defer=tot$sat27, sat.proc=tot$sat28, sat.wait=tot$sat29, sat.transport=tot$sat210, sat.other=tot$sat211, dm.months=tot$dm2months, dm.yrs=tot$dm2yrs, oral.dm.med=tot$dm22, own.bg.24=tot$dm3d, own.bg.52=tot$dm3w, own.bg.12=tot$dm3m, hp.bg.24=tot$dm41, hp.bg.52=tot$dm42, hp.bg.12=tot$dm43, strips=tot$dm3a, paid.strips=tot$dm3b, dm3c=tot$dm3c, strip.acc=tot$dm3d1, bg.cost=tot$dm5, tcad=tot$tcad, tcew=tot$tcew, tcop=tot$tcop, wmtt=tot$wmtt, tmtt=tot$tmtt, thtt=tot$thtt, phtt=tot$phtt, chtt=tot$chtt, wmtc=tot$wmtc, tmtc=tot$tmtc, thtc=tot$thtc, phtc=tot$phtc, chtc=tot$chtc, pyadb=tot$pyadb, pyewb=tot$pyewb, pycb=tot$pycb, tpyad=tot$tpyad, tyew1=tot$tyew1, tyop1=tot$tyop1, copy=tot$copy, pay=tot$pay, trad=tot$trad, trew=tot$trew, trop=tot$trop, pead=tot$pead, peew=tot$peew, peop=tot$peop, dm41 = tot$dm41, dm42 = tot$dm42, dm43 = tot$dm43, ins.dr=tot$dm6a1a, ins.exp=tot$dm6a1b, ins.out=tot$dm6a2, ins.qual=tot$dm6a3, ins.syr=tot$dm6a4, ins.syr.exp=tot$dm6a5, ins.afraid=tot$dm6a6, ins.how=tot$dm6a7, ins.when=tot$dm6a8, ins.why=tot$dm6a9, ins.testing=tot$dm6a10, ins.dr=tot$dm6a11, ins.other=tot$dm6a12, dsme=tot$dm7, dm8=tot$dm8, ed.eye.exam=tot$dm9, ed.microal=tot$dm10, ed.foot=tot$dm11, dm6=tot$dm6, dm6h=tot$dm6h, meop1=tot$meop1, hu1=tot$hu1, hu2=tot$hu2, hu3=tot$hu3, hu4=tot$hu4, hu5=tot$hu5, hu6=tot$hu6, hu7=tot$hu7, hu8=tot$hu8, hu9=tot$hu9, hu10=tot$hu10, hu11=tot$hu11, hu12=tot$hu12, hu13=tot$hu13, hu14=tot$hu14, hu15=tot$hu15, hu16=tot$hu16, hu17=tot$hu17, hu18=tot$hu18, hu19=tot$hu19, hu20=tot$hu20, hu21=tot$hu21, hu22=tot$hu22, hu23=tot$hu23, hu24=tot$hu24, hu25=tot$hu25, hu26=tot$hu26, hu27=tot$hu27, hu28=tot$hu28, hu29=tot$hu29, hu30=tot$hu30, hu31=tot$hu31, hu32=tot$hu32, hu33=tot$hu33, hu34=tot$hu34, hu35=tot$hu35, hu36=tot$hu36, hu37=tot$hu37, hu38=tot$hu38, hu39=tot$hu39, hu40=tot$hu40, hu41=tot$hu41, ir1=tot$ir1, ir2=tot$ir2, ir3=tot$ir3, ir5=tot$ir5, ir6=tot$ir6, ir7=tot$ir7, ir8=tot$ir8, if1a=tot$if1a, if2a=tot$if2a, if3a=tot$if3a, if5a=tot$if5a, if6a=tot$if6a, if8a=tot$if8a, wrk1c=tot$wrk1, wrk2c=tot$wrk2, wrk3c=tot$wrk3, wrk9c=tot$wrk9, wrk5c=tot$wrk5, wrk10c=tot$wrk11, wrk11c=tot$wrk11, wrk12c=tot$wrk12, wrk6c=tot$wrk6, wrk7c=tot$wrk7, wrk8c=tot$wrk8, wrk13c=tot$wrk13, wth1c=tot$wth1, wth2c=tot$wth2, wth3c=tot$wth3, wth4c=tot$wth4, wth5c=tot$wth5, wth6c=tot$wth6, wth7c=tot$wth7, wth8c=tot$wth8, wth9c=tot$wth9, wth10c=tot$wth10, wth12c=tot$wth12, wth13c=tot$wth13) x <- unique(x) ## 8. infectious Disease x$any.inf <- "No" x$any.inf[x$tb == "Yes" | x$malaria == "Yes" | x$flu == "Yes" | x$pneumonia == "Yes" | x$diarrhea == "Yes" | x$cold == "Yes" | x$typhoid == "Yes"] <- "Yes" x$any.inf[is.na(x$tb) | is.na(x$malaria) | is.na(x$flu) | is.na(x$pneumonia) | is.na(x$diarrhea) | is.na(x$cold) | is.na(x$typhoid)] <- NA ## 9. cost variables and hospital use ## any hospital use a <- x[!is.na(x$hosp.ad) | !is.na(x$hosp.ew) | !is.na(x$hosp.op),] a$hosp.ad[is.na(a$hosp.ad)] <- 0 a$hosp.ew[is.na(a$hosp.ew)] <- 0 a$hosp.op[is.na(a$hosp.op)] <- 0 a$any.hosp <- a$hosp.ad + a$hosp.ew + a$hosp.op a$over.hosp <- a$hosp.ad a <- a[c("ID", "any.hosp", "over.hosp")] num.rows <- nrow(x) x <- merge(a, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) ## annual outpatient visits x$hosp.op.yr <- x$hosp.op * 4 ## annual emergency room visits x$hosp.ew.yr <- x$hosp.ew * 4 ## annual overnight admissions to the hospital (multiplication method) x$hosp.ad.yr <- x$hosp.ad * 4 ## annual overnight admissions (addition method) x$hosp.365[is.na(x$hosp.365)] <- 0 x$hosp.yr.add <- x$hosp.ad + x$hosp.365 ## duration hospital care hos <- x[!is.na(x$hosp.ad) | !is.na(x$hosp.ew),] hos$niwa[is.na(hos$niwa)] <- 0 hos$nicu[is.na(hos$nicu)] <- 0 hos$niad[is.na(hos$niad)] <- 0 hos$daew[is.na(hos$daew)] <- 0 hos$hosp.ad[is.na(hos$hosp.ad)] <- 0 hos$hosp.ew[is.na(hos$hosp.ew)] <- 0 hos$dur.hosp <- (hos$hosp.ad*hos$niwa) + (hos$hosp.ew*hos$nicu) + (hos$daew/24) hos <- hos[c("ID", "dur.hosp")] num.rows <- nrow(x) x <- merge(hos, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) ## annual duration hospital care x$dur.hosp.yr <- x$dur.hosp * 4 ## duration of most recent overnight hospital admit x$nights.hosp <- x$niwa + x$nicu ## annual duration of overnight admits x$nights.hosp.yr <- x$nights.hosp * x$hosp.ad.yr ## 10 Non-hospital utilization noh <- x[!is.na(x$wm.visit) | !is.na(x$tm.visit) | !is.na(x$th.visit) | !is.na(x$ph.visit) | !is.na(x$ch.visit),] noh$wm.visit[is.na(noh$wm.visit)] <- 0 noh$tm.visit[is.na(noh$tm.visit)] <- 0 noh$th.visit[is.na(noh$th.visit)] <- 0 noh$ph.visit[is.na(noh$ph.visit)] <- 0 noh$ch.visit[is.na(noh$ch.visit)] <- 0 noh$total.nohos <- noh$wm.visit + noh$tm.visit + noh$th.visit + noh$ch.visit noh <- noh[c("ID", "total.nohos")] num.rows <- nrow(x) x <- merge(noh, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) ##annual total western med. visit x$wm.visit.yr <- x$wm.visit * 4 ## annual total Chinese Medicine visit x$tm.visit.yr <- x$tm.visit * 4 ## annual total traditional healer visit x$th.visit.yr <- x$th.visit * 4 ## annual total community health clinic visit x$ch.visit.yr <- x$ch.visit * 4 ## annual total nonhos x$total.nohos.yr <- x$total.nohos * 4 ## 11. direct medical costs - hospital use and non-hospital use ## out of pocket - hospital overnight admission last visit oop <- x[!is.na(x$tpyad), c("ID","tpyad")] oop$tpyad[is.na(oop$tpyad)] <- 0 oop$hoop.ad <- oop$tpyad oop <- oop[c("ID", "hoop.ad")] num.rows <- nrow(x) x <- merge(oop, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) ##Annual Out of Pocket - hospital overnight admission x$hoop.ad.yr <- x$hoop.ad * x$hosp.ad.yr ## out of pocket - non-hospital outpatient last visit oop1 <- x[!is.na(x$tyop1) | is.na(x$wmco) | is.na(x$chco) | is.na(x$phco),] oop1$tyop1[is.na(oop1$tyop1)] <- 0 oop1$wmco[is.na(oop1$wmco)] <- 0 oop1$chco[is.na(oop1$chco)] <- 0 oop1$phco[is.na(oop1$phco)] <- 0 oop1$hoop.op <- oop1$tyop1 + oop1$wmco + oop1$chco + oop1$phco oop1 <- oop1[c("ID", "hoop.op")] num.rows <- nrow(x) x <- merge(oop1, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) ## Annual out of pocket - Outpatient Visits x$hoop.op.yr <- x$hoop.op * x$hosp.op.yr ## out of pocket - Emergency Room last visit oop2 <- x[!is.na(x$tyew1), c("ID", "tyew1")] oop2$tyew1[is.na(oop2$tyew1)] <- 0 oop2$hoop.ew <- oop2$tyew1 oop2 <- oop2[c("ID", "hoop.ew")] num.rows <- nrow(x) x <- merge(oop2, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) ## Annual out of pocket - Emergency Room Visits x$hoop.ew.yr <- x$hoop.ew * x$hosp.ew.yr ## out of pocket - hospital use last 90 days hoop <- x[!is.na(x$pyad) | !is.na(x$hosp.ad) | !is.na(x$pyew) | !is.na(x$hosp.ew) | !is.na(x$pypc) | !is.na(x$hosp.op), c("ID", "pyad", "hosp.ad", "pyew", "hosp.ew", "pypc", "hosp.op")] hoop$pyad[is.na(hoop$pyad)] <- 0 hoop$pyew[is.na(hoop$pyew)] <- 0 hoop$pyop[is.na(hoop$pypc)] <- 0 hoop$pyad[is.na(hoop$pyad)] <- 0 hoop$hosp.ad[is.na(hoop$hosp.ad)] <- 0 hoop$hosp.ew[is.na(hoop$hosp.ew)] <- 0 hoop$hosp.op[is.na(hoop$hosp.op)] <- 0 hoop$hoop.90 <- (hoop$pyad * hoop$hosp.ad) + (hoop$pyew * hoop$hosp.ew) + (hoop$pypc * hoop$hosp.op) hoop <- hoop[c("ID", "hoop.90")] num.rows <- nrow(x) x <- merge(hoop, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) ## annual out of pocket - hospital use x$hoop.yr <- x$hoop.90 * 4 ## out of pocket - nonhospital use last 90 days noop <- x[!is.na(x$wm90) | !is.na(x$wmco) | !is.na(x$tm90) | !is.na(x$tmco) | !is.na(x$ph90) | !is.na(x$phco) | !is.na(x$ch90) | !is.na(x$chco) | !is.na(x$th90) | !is.na(x$thco), c("ID", "wm90", "wmco", "tm90", "tmco", "ch90", "chco", "th90", "thco")] noop$wm90[is.na(noop$wm90)] <- 0 noop$wmco[is.na(noop$wmco)] <- 0 noop$tm90[is.na(noop$tm90)] <- 0 noop$tmco[is.na(noop$tmco)] <- 0 noop$ch90[is.na(noop$ch90)] <- 0 noop$chco[is.na(noop$chco)] <- 0 noop$th90[is.na(noop$th90)] <- 0 noop$thco[is.na(noop$thco)] <- 0 noop$noop.90 <- (noop$wm90 * noop$wmco) + (noop$tm90 * noop$tmco) + (noop$th90 * noop$thco) + (noop$ch90 * noop$chco) noop <- noop[c("ID", "noop.90")] num.rows <- nrow(x) x <- merge(noop, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) ## 12. medications ##Primary Medicine Categories x$any.anticoag <- "No" x$any.anticoag[x$aspn == "Yes" | x$m1a == "clopid" | x$m2a == "clopid" | x$m3a == "clopid" | x$m4a == "clopid" | x$m5a == "clopid" | x$m6a == "clopid" | x$m7a == "clopid" | x$m88a == "clopid" | x$m99a == "clopid" | x$m1a == "warf" | x$m2a == "warf" | x$m3a == "warf" | x$m4a == "warf" | x$m5a == "warf" | x$m6a == "warf" | x$m7a == "warf" | x$m88a == "warf" | x$m99a == "warf"] <- "Yes" x$no.asp.anticoag <- "No" x$no.asp.anticoag[x$m1a == "clopid" | x$m2a == "clopid" | x$m3a == "clopid" | x$m4a == "clopid" | x$m5a == "clopid" | x$m6a == "clopid" | x$m7a == "clopid" | x$m88a == "clopid" | x$m99a == "clopid" | x$m1a == "warf" | x$m2a == "warf" | x$m3a == "warf" | x$m4a == "warf" | x$m5a == "warf" | x$m6a == "warf" | x$m7a == "warf" | x$m88a == "warf" | x$m99a == "warf"] <- "Yes" x$asp <- "No" x$asp[x$aspn == "Yes"] <- "Yes" x$clopid <- "No" x$clopid[x$m1a == "clopid" | x$m2a == "clopid" | x$m3a == "clopid" | x$m4a == "clopid" | x$m5a == "clopid" | x$m6a == "clopid" | x$m7a == "clopid" | x$m88a == "clopid" | x$m99a == "clopid"] <- "Yes" x$warf <- "No" x$warf[x$m1a == "warf" | x$m2a == "warf" | x$m3a == "warf" | x$m4a == "warf" | x$m5a == "warf" | x$m6a == "warf" | x$m7a == "warf" | x$m88a == "warf" | x$m99a == "warf"] <- "Yes" x$any.bp <- "No" x$any.bp[x$m1a == "ace" | x$m2a == "ace" | x$m3a == "ace" | x$m4a == "ace" | x$m5a == "ace" | x$m6a == "ace" | x$m7a == "ace" | x$m88a == "ace" | x$m99a == "ace" | x$m1a == "arb" | x$m2a == "arb" | x$m3a == "arb" | x$m4a == "arb" | x$m5a == "arb"| x$m6a == "arb" | x$m7a == "arb" | x$m88a == "arb" | x$m99a == "arb" | x$m1a == "bb" | x$m2a == "bb" | x$m3a == "bb" | x$m4a == "bb" | x$m5a == "bb" | x$m6a == "bb" | x$m7a == "bb" | x$m88a == "bb" | x$m99a == "bb" | x$m1a == "ccb" | x$m2a == "ccb" | x$m3a == "ccb" | x$m4a == "ccb" | x$m5a == "ccb" | x$m6a == "ccb" | x$m7a == "ccb" | x$m88a == "ccb" | x$m99a == "ccb" | x$m1a == "diur" | x$m2a == "diur" | x$m3a == "diur" | x$m4a == "diur" | x$m5a == "diur" | x$m6a == "diur" | x$m7a == "diur" | x$m88a == "diur" | x$m99a == "diur" | x$m1a == "reserpine" | x$m2a == "reserpine" | x$m3a == "reserpine" | x$m4a == "reserpine" | x$m5a == "reserpine" | x$m6a == "reserpine" | x$m7a == "reserpine" | x$m88a == "reserpine" | x$m99a == "reserpine" | x$m1a == "combin" | x$m2a == "combin" | x$m3a == "combin" | x$m4a == "combin" | x$m5a == "combin" | x$m6a == "combin" | x$m7a == "combin" | x$m88a == "combin" | x$m99a == "combin" | x$m1a == "clonidine" | x$m2a == "clonidine" | x$m3a == "clonidine" | x$m4a == "clonidine" | x$m5a == "clonidine" | x$m6a == "clonidine" | x$m7a == "clonidine" | x$m88a == "clonidine" | x$m99a == "clonidine"] <- "Yes" x$ace <- "No" x$ace[x$m1a == "ace" | x$m2a == "ace" | x$m3a == "ace" | x$m4a == "ace" | x$m5a == "ace" | x$m6a == "ace" | x$m7a == "ace" | x$m88a == "ace" | x$m99a == "ace"] <- "Yes" x$tzd <- "No" x$tzd[x$m1a == "tzd" | x$m2a == "tzd" | x$m3a == "tzd" | x$m4a == "tzd" | x$m5a == "tzd" | x$m6a == "tzd" | x$m7a == "tzd" | x$m88a == "tzd" | x$m99a == "tzd"] <- "Yes" x$arb <- "No" x$arb[x$m1a == "arb" | x$m2a == "arb" | x$m3a == "arb" | x$m4a == "arb" | x$m5a == "arb"| x$m6a == "arb" | x$m7a == "arb" | x$m88a == "arb" | x$m99a == "arb"] <- "Yes" x$bb <- "No" x$bb[x$m1a == "bb" | x$m2a == "bb" | x$m3a == "bb" | x$m4a == "bb" | x$m5a == "bb" | x$m6a == "bb" | x$m7a == "bb" | x$m88a == "bb" | x$m99a == "bb"] <- "Yes" x$ccb <- "No" x$ccb[x$m1a == "ccb" | x$m2a == "ccb" | x$m3a == "ccb" | x$m4a == "ccb" | x$m5a == "ccb" | x$m6a == "ccb" | x$m7a == "ccb" | x$m88a == "ccb" | x$m99a == "ccb"] <- "Yes" x$diur <- "No" x$diur[x$m1a == "diur" | x$m2a == "diur" | x$m3a == "diur" | x$m4a == "diur" | x$m5a == "diur" | x$m6a == "diur" | x$m7a == "diur" | x$m88a == "diur" | x$m99a == "diur"] <- "Yes" x$reserpine <- "No" x$reserpine[x$m1a == "reserpine" | x$m2a == "reserpine" | x$m3a == "reserpine" | x$m4a == "reserpine" | x$m5a == "reserpine" | x$m6a == "reserpine" | x$m7a == "reserpine" | x$m88a == "reserpine" | x$m99a == "reserpine"] <- "Yes" x$other.bp <- "No" x$other.bp[x$m1a == "clonidine" | x$m2a == "clonidine" | x$m3a == "clonidine" | x$m4a == "clonidine" | x$m5a == "clonidine" | x$m6a == "clonidine" | x$m7a == "clonidine" | x$m88a == "clonidine" | x$m99a == "clonidine" | x$m1a == "combin" | x$m2a == "combin" | x$m3a == "combin" | x$m4a == "combin" | x$m5a == "combin" | x$m6a == "combin" | x$m7a == "combin" | x$m88a == "combin" | x$m99a == "combin" | x$m1a == "reserpine" | x$m2a == "reserpine" | x$m3a == "reserpine" | x$m4a == "reserpine" | x$m5a == "reserpine" | x$m6a == "reserpine" | x$m7a == "reserpine" | x$m88a == "reserpine" | x$m99a == "reserpine"] <- "Yes" x$combin <- "No" x$combin[x$m1a == "combin" | x$m2a == "combin" | x$m3a == "combin" | x$m4a == "combin" | x$m5a == "combin" | x$m6a == "combin" | x$m7a == "combin" | x$m88a == "combin" | x$m99a == "combin"] <- "Yes" x$clonidine <- "No" x$clonidine[x$m1a == "clonidine" | x$m2a == "clonidine" | x$m3a == "clonidine" | x$m4a == "clonidine" | x$m5a == "clonidine" | x$m6a == "clonidine" | x$m7a == "clonidine" | x$m88a == "clonidine" | x$m99a == "clonidine"] <- "Yes" x$other.gllow <- "No" x$other.gllow[x$m1a == "ginide" | x$m2a == "ginide" | x$m3a == "ginide" | x$m4a == "ginide" | x$m5a == "ginide" | x$m6a == "ginide" | x$m7a == "ginide" | x$m88a == "ginide" | x$m99a == "ginide" | x$m1a == "co" | x$m2a == "co" | x$m3a == "co" | x$m4a == "co" | x$m5a == "co" | x$m6a == "co" | x$m7a == "co" | x$m88a == "co" | x$m99a == "co"] <- "Yes" x$any.gllow <- "No" x$any.gllow[x$m1a == "insulin" | x$m2a == "insulin" | x$m3a == "insulin" | x$m4a == "insulin" | x$m5a == "insulin" | x$m6a == "insulin" | x$m7a == "insulin" | x$m88a == "insulin" | x$m99a == "insulin" | x$m1a == "su" | x$m2a == "su" | x$m3a == "su" | x$m4a == "su" | x$m5a == "su" | x$m6a == "su" | x$m7a == "su" | x$m88a == "su" | x$m99a == "su" | x$m1a == "met" | x$m2a == "met" | x$m3a == "met" | x$m4a == "met" | x$m5a == "met" | x$m6a == "met" | x$m7a == "met" | x$m88a == "met" | x$m99a == "met" | x$m1a == "acar" | x$m2a == "acar" | x$m3a == "acar" | x$m4a == "acar" | x$m5a == "acar" | x$m6a == "acar" | x$m7a == "acar" | x$m88a == "acar" | x$m99a == "acar" | x$m1a == "ginide" | x$m2a == "ginide" | x$m3a == "ginide" | x$m4a == "ginide" | x$m5a == "ginide" | x$m6a == "ginide" | x$m7a == "ginide" | x$m88a == "ginide" | x$m99a == "ginide" | x$m1a == "co" | x$m2a == "co" | x$m3a == "co" | x$m4a == "co" | x$m5a == "co" | x$m6a == "co" | x$m7a == "co" | x$m88a == "co" | x$m99a == "co"] <- "Yes" x$no.ins.gllow <- "No" x$no.ins.gllow[x$m1a == "su" | x$m2a == "su" | x$m3a == "su" | x$m4a == "su" | x$m5a == "su" | x$m6a == "su" | x$m7a == "su" | x$m88a == "su" | x$m99a == "su" | x$m1a == "met" | x$m2a == "met" | x$m3a == "met" | x$m4a == "met" | x$m5a == "met" | x$m6a == "met" | x$m7a == "met" | x$m88a == "met" | x$m99a == "met" | x$m1a == "acar" | x$m2a == "acar" | x$m3a == "acar" | x$m4a == "acar" | x$m5a == "acar" | x$m6a == "acar" | x$m7a == "acar" | x$m88a == "acar" | x$m99a == "acar" | x$m1a == "ginide" | x$m2a == "ginide" | x$m3a == "ginide" | x$m4a == "ginide" | x$m5a == "ginide" | x$m6a == "ginide" | x$m7a == "ginide" | x$m88a == "ginide" | x$m99a == "ginide" | x$m1a == "co" | x$m2a == "co" | x$m3a == "co" | x$m4a == "co" | x$m5a == "co" | x$m6a == "co" | x$m7a == "co" | x$m88a == "co" | x$m99a == "co"] <- "Yes" x$ins <- "No" x$ins[x$m1a == "insulin" | x$m2a == "insulin" | x$m3a == "insulin" | x$m4a == "insulin" | x$m5a == "insulin" | x$m6a == "insulin" | x$m7a == "insulin" | x$m88a == "insulin" | x$m99a == "insulin"] <- "Yes" x$su <- "No" x$su[x$m1a == "su" | x$m2a == "su" | x$m3a == "su" | x$m4a == "su" | x$m5a == "su" | x$m6a == "su" | x$m7a == "su" | x$m88a == "su" | x$m99a == "su"] <- "Yes" x$met <- "No" x$met[x$m1a == "met" | x$m2a == "met" | x$m3a == "met" | x$m4a == "met" | x$m5a == "met" | x$m6a == "met" | x$m7a == "met" | x$m88a == "met" | x$m99a == "met"] <- "Yes" x$acar <- "No" x$acar[x$m1a == "acar" | x$m2a == "acar" | x$m3a == "acar" | x$m4a == "acar" | x$m5a == "acar" | x$m6a == "acar" | x$m7a == "acar" | x$m88a == "acar" | x$m99a == "acar"] <- "Yes" x$ginide <- "No" x$ginide[x$m1a == "ginide" | x$m2a == "ginide" | x$m3a == "ginide" | x$m4a == "ginide" | x$m5a == "ginide" | x$m6a == "ginide" | x$m7a == "ginide" | x$m88a == "ginide" | x$m99a == "ginide"] <- "Yes" x$co <- "No" x$co[x$m1a == "co" | x$m2a == "co" | x$m3a == "co" | x$m4a == "co" | x$m5a == "co" | x$m6a == "co" | x$m7a == "co" | x$m88a == "co" | x$m99a == "co"] <- "Yes" x$any.dmdrug <- "No" x$any.dmdrug[x$aspn == "Yes" | x$m1a == "clopid" | x$m2a == "clopid" | x$m3a == "clopid" | x$m4a == "clopid" | x$m5a == "clopid" | x$m6a == "clopid" | x$m7a == "clopid" | x$m88a == "clopid" | x$m99a == "clopid" | x$m1a == "warf" | x$m2a == "warf" | x$m3a == "warf" | x$m4a == "warf" | x$m5a == "warf" | x$m6a == "warf" | x$m7a == "warf" | x$m88a == "warf" | x$m99a == "warf" | x$m1a == "ace" | x$m2a == "ace" | x$m3a == "ace" | x$m4a == "ace" | x$m5a == "ace" | x$m6a == "ace" | x$m7a == "ace" | x$m88a == "ace" | x$m99a == "ace" | x$m1a == "arb" | x$m2a == "arb" | x$m3a == "arb" | x$m4a == "arb" | x$m5a == "arb"| x$m6a == "arb" | x$m7a == "arb" | x$m88a == "arb" | x$m99a == "arb" | x$m1a == "bb" | x$m2a == "bb" | x$m3a == "bb" | x$m4a == "bb" | x$m5a == "bb" | x$m6a == "bb" | x$m7a == "bb" | x$m88a == "bb" | x$m99a == "bb" | x$m1a == "ccb" | x$m2a == "ccb" | x$m3a == "ccb" | x$m4a == "ccb" | x$m5a == "ccb" | x$m6a == "ccb" | x$m7a == "ccb" | x$m88a == "ccb" | x$m99a == "ccb" | x$m1a == "diur" | x$m2a == "diur" | x$m3a == "diur" | x$m4a == "diur" | x$m5a == "diur" | x$m6a == "diur" | x$m7a == "diur" | x$m88a == "diur" | x$m99a == "diur" | x$m1a == "reserpine" | x$m2a == "reserpine" | x$m3a == "reserpine" | x$m4a == "reserpine" | x$m5a == "reserpine" | x$m6a == "reserpine" | x$m7a == "reserpine" | x$m88a == "reserpine" | x$m99a == "reserpine" | x$m1a == "combin" | x$m2a == "combin" | x$m3a == "combin" | x$m4a == "combin" | x$m5a == "combin" | x$m6a == "combin" | x$m7a == "combin" | x$m88a == "combin" | x$m99a == "combin" | x$m1a == "insulin" | x$m2a == "insulin" | x$m3a == "insulin" | x$m4a == "insulin" | x$m5a == "insulin" | x$m6a == "insulin" | x$m7a == "insulin" | x$m88a == "insulin" | x$m99a == "insulin" | x$m1a == "su" | x$m2a == "su" | x$m3a == "su" | x$m4a == "su" | x$m5a == "su" | x$m6a == "su" | x$m7a == "su" | x$m88a == "su" | x$m99a == "su" | x$m1a == "met" | x$m2a == "met" | x$m3a == "met" | x$m4a == "met" | x$m5a == "met" | x$m6a == "met" | x$m7a == "met" | x$m88a == "met" | x$m99a == "met" | x$m1a == "acar" | x$m2a == "acar" | x$m3a == "acar" | x$m4a == "acar" | x$m5a == "acar" | x$m6a == "acar" | x$m7a == "acar" | x$m88a == "acar" | x$m99a == "acar" | x$m1a == "ginide" | x$m2a == "ginide" | x$m3a == "ginide" | x$m4a == "ginide" | x$m5a == "ginide" | x$m6a == "ginide" | x$m7a == "ginide" | x$m88a == "ginide" | x$m99a == "ginide" | x$m1a == "statin" | x$m2a == "statin" | x$m3a == "statin" | x$m4a == "statin" | x$m5a == "statin" | x$m6a == "statin" | x$m7a == "statin"| x$m88a == "statin" | x$m99a == "statin" | x$m1a == "clonidine" | x$m2a == "clonidine" | x$m3a == "clonidine" | x$m4a == "clonidine" | x$m5a == "clonidine" | x$m6a == "clonidine" | x$m7a == "clonidine" | x$m88a == "clonidine" | x$m99a == "clonidine" | x$m1a == "co" | x$m2a == "co" | x$m3a == "co" | x$m4a == "co" | x$m5a == "co" | x$m6a == "co" | x$m7a == "co" | x$m88a == "co" | x$m99a == "co"] <- "Yes" x$any.herb <- "No" x$any.herb[x$m1a == "herb" | x$m2a == "herb" | x$m3a == "herb" | x$m4a == "herb" | x$m5a == "herb" | x$m6a == "herb" | x$m7a == "herb"|x$m1a == "herbb" | x$m2a == "herbb" | x$m3a == "herbb" | x$m4a == "herbb" | x$m5a == "herbb" | x$m6a == "herbb" | x$m7a == "herbb"|x$m1a == "herbd" | x$m2a == "herbd" | x$m3a == "herbd" | x$m4a == "herbd" | x$m5a == "herbd" | x$m6a == "herbd" | x$m7a == "herbd"] <- "Yes" x$herb <- "No" x$herb[x$m1a == "herb" | x$m2a == "herb" | x$m3a == "herb" | x$m4a == "herb" | x$m5a == "herb" | x$m6a == "herb" | x$m7a == "herb"] <- "Yes" x$herbb <- "No" x$herbb[x$m1a == "herbb" | x$m2a == "herbb" | x$m3a == "herbb" | x$m4a == "herbb" | x$m5a == "herbb" | x$m6a == "herbb" | x$m7a == "herbb"] <- "Yes" x$herbd <- "No" x$herbd[x$m1a == "herbd" | x$m2a == "herbd" | x$m3a == "herbd" | x$m4a == "herbd" | x$m5a == "herbd" | x$m6a == "herbd" | x$m7a == "herbd"] <- "Yes" x$any.lipid <- "No" x$any.lipid[x$m1a == "statin" | x$m2a == "statin" | x$m3a == "statin" | x$m4a == "statin" | x$m5a == "statin" | x$m6a == "statin" | x$m7a == "statin"| x$m88a == "statin" | x$m99a == "statin" | x$m1a == "niacin" | x$m2a == "niacin" | x$m3a == "niacin" | x$m4a == "niacin" | x$m5a == "niacin" | x$m6a == "niacin" | x$m7a == "niacin"| x$m88a == "niacin" | x$m99a == "niacin" | x$m1a == "fibrate" | x$m2a == "fibrate" | x$m3a == "fibrate" | x$m4a == "fibrate" | x$m5a == "fibrate" | x$m6a == "fibrate" | x$m7a == "fibrate"| x$m88a == "fibrate" | x$m99a == "fibrate"] <- "Yes" x$statin <- "No" x$statin[x$m1a == "statin" | x$m2a == "statin" | x$m3a == "statin" | x$m4a == "statin" | x$m5a == "statin" | x$m6a == "statin" | x$m7a == "statin"| x$m88a == "statin" | x$m99a == "statin"] <- "Yes" x$fibrate <- "No" x$fibrate[x$m1a == "fibrate" | x$m2a == "fibrate" | x$m3a == "fibrate" | x$m4a == "fibrate" | x$m5a == "fibrate" | x$m6a == "fibrate" | x$m7a == "fibrate"| x$m88a == "fibrate" | x$m99a == "fibrate"] <- "Yes" x$niacin <- "No" x$niacin[x$m1a == "niacin" | x$m2a == "niacin" | x$m3a == "niacin" | x$m4a == "niacin" | x$m5a == "niacin" | x$m6a == "niacin" | x$m7a == "niacin"| x$m88a == "niacin" | x$m99a == "niacin"] <- "Yes" x$other.lipid <- "No" x$other.lipid[x$m1a == "fibrate" | x$m2a == "fibrate" | x$m3a == "fibrate" | x$m4a == "fibrate" | x$m5a == "fibrate" | x$m6a == "fibrate" | x$m7a == "fibrate"| x$m88a == "fibrate" | x$m99a == "fibrate" | x$m1a == "niacin" | x$m2a == "niacin" | x$m3a == "niacin" | x$m4a == "niacin" | x$m5a == "niacin" | x$m6a == "niacin" | x$m7a == "niacin"| x$m88a == "niacin" | x$m99a == "niacin"] <- "Yes" ##Other Categories: met.su, ins, other.gl, statin, asp, other x$met.su <- "No" x$met.su[x$m1a == "su" | x$m2a == "su" | x$m3a == "su" | x$m4a == "su" | x$m5a == "su" | x$m6a == "su" | x$m7a == "su" | x$m88a == "su" | x$m99a == "su" | x$m1a == "met" | x$m2a == "met" | x$m3a == "met" | x$m4a == "met" | x$m5a == "met" | x$m6a == "met" | x$m7a == "met" | x$m88a == "met" | x$m99a == "met"] <- "Yes" x$no.ins.gllow <- "No" x$no.ins.gllow[x$m1a == "su" | x$m2a == "su" | x$m3a == "su" | x$m4a == "su" | x$m5a == "su" | x$m6a == "su" | x$m7a == "su" | x$m88a == "su" | x$m99a == "su" | x$m1a == "met" | x$m2a == "met" | x$m3a == "met" | x$m4a == "met" | x$m5a == "met" | x$m6a == "met" | x$m7a == "met" | x$m88a == "met" | x$m99a == "met" | x$m1a == "acar" | x$m2a == "acar" | x$m3a == "acar" | x$m4a == "acar" | x$m5a == "acar" | x$m6a == "acar" | x$m7a == "acar" | x$m88a == "acar" | x$m99a == "acar" | x$m1a == "ginide" | x$m2a == "ginide" | x$m3a == "ginide" | x$m4a == "ginide" | x$m5a == "ginide" | x$m6a == "ginide" | x$m7a == "ginide" | x$m88a == "ginide" | x$m99a == "ginide"] <- "Yes" x$other.gl <- "No" x$other.gl[x$m1a == "acar" | x$m2a == "acar" | x$m3a == "acar" | x$m4a == "acar" | x$m5a == "acar" | x$m6a == "acar" | x$m7a == "acar" | x$m88a == "acar" | x$m99a == "acar" | x$m1a == "ginide" | x$m2a == "ginide" | x$m3a == "ginide" | x$m4a == "ginide" | x$m5a == "ginide" | x$m6a == "ginide" | x$m7a == "ginide" | x$m88a == "ginide" | x$m99a == "ginide"] <- "Yes" x$statin <- "No" x$statin[x$m1a == "statin" | x$m2a == "statin" | x$m3a == "statin" | x$m4a == "statin" | x$m5a == "statin" | x$m6a == "statin" | x$m7a == "statin"| x$m88a == "statin" | x$m99a == "statin"] <- "Yes" x$psych <- "No" x$psych[x$m1a == "psycho" | x$m2a == "psycho" | x$m3a == "psycho" | x$m4a == "psycho" | x$m5a == "psycho" | x$m6a == "psycho" | x$m7a == "psycho" | x$m88a == "psycho" | x$m99a == "psycho"] <- "Yes" x$gastric <- "No" x$gastric[x$m1a == "gastric" | x$m2a == "gastric" | x$m3a == "gastric" | x$m4a == "gastric" | x$m5a == "gastric" | x$m6a == "gastric" | x$m7a == "gastric" | x$m88a == "gastric" | x$m99a == "gastric"] <- "Yes" x$anal <- "No" x$anal[x$m1a == "anal" | x$m2a == "anal" | x$m3a == "anal" | x$m4a == "anal" | x$m5a == "anal" | x$m6a == "anal" | x$m7a == "anal" | x$m88a == "anal" | x$m99a == "anal"] <- "Yes" x$Ca <- "No" x$Ca[x$m1a == "Ca" | x$m2a == "anal" | x$m3a == "Ca" | x$m4a == "Ca" | x$m5a == "Ca" | x$m6a == "Ca" | x$m7a == "Ca" | x$m88a == "Ca" | x$m99a == "Ca"] <- "Yes" x$vit <- "No" x$vit[x$m1a == "vit" | x$m2a == "vit" | x$m3a == "vit" | x$m4a == "vit" | x$m5a == "vit" | x$m6a == "vit" | x$m7a == "vit" | x$m88a == "vit" | x$m99a == "vit"] <- "Yes" x$any.vit <- "No" x$any.vit[x$m1a == "Ca" | x$m2a == "anal" | x$m3a == "Ca" | x$m4a == "Ca" | x$m5a == "Ca" | x$m6a == "Ca" | x$m7a == "Ca" | x$m88a == "Ca" | x$m99a == "Ca"|x$m1a == "vit" | x$m2a == "vit" | x$m3a == "vit" | x$m4a == "vit" | x$m5a == "vit" | x$m6a == "vit" | x$m7a == "vit" | x$m88a == "vit" | x$m99a == "vit"] <- "Yes" x$other <- "No" x$other[x$m1a == "antibiotic" | x$m2a == "antibiotic" | x$m3a == "antibiotic" | x$m4a == "antibiotic" | x$m5a == "antibiotic"| x$m6a == "antibiotic" | x$m7a == "antibiotic" | x$m88a == "antibiotic" | x$m99a == "antibiotic" | x$m1a == "other" | x$m2a == "other" | x$m3a == "other" | x$m4a == "other" | x$m5a == "other" | x$m6a == "other" | x$m7a == "other" | x$m88a == "other" | x$m99a == "other"] <- "Yes" x$other.nondm <- "No" x$other.nondm[x$other == "Yes" | x$psych == "Yes" | x$anal == "Yes" | x$gastric == "Yes" | x$antibiotic == "Yes"] <- "Yes" x$any.drug <- "No" x$any.drug[x$other.nondm == "Yes" | x$any.dmdrug == "Yes"] <- "Yes" ## 13. multiple DM drugs for (i in 1:nrow(x)) { x$many.drug.dm[i] <- sum(yesno(x$statin[i]), yesno(x$fibrate[i]), yesno(x$niacin[i]), yesno(x$asp[i]), yesno(x$clopid[i]), yesno(x$warf[i]), yesno(x$ace[i]), yesno(x$ccb[i]), yesno(x$bb[i]), yesno(x$arb[i]), yesno(x$reserpine[i]), yesno(x$combin[i]), yesno(x$clonidine[i]), yesno(x$insulin[i]), yesno(x$su[i]), yesno(x$met[i]), yesno(x$acar[i]), yesno(x$diur[i]), yesno(x$ginide[i]), yesno(x$co[i]), yesno(x$tzd[i]), na.rm = TRUE) } ## Multiple NonDM Drugs for (i in 1:nrow(x)) { x$many.drug.nondm[i] <- sum(yesno(x$other[i]), yesno(x$gastric[i]), yesno(x$anal[i]), yesno(x$psych[i]), na.rm = TRUE) } ## Multiple Drug Total x$total.drug <- x$many.drug.dm + x$many.drug.nondm ## 14. Location of Drug Purchase x$drug.loc.pu[x$m1g == "hospital pharmacy" | x$m2g == "hospital pharmacy" | x$m3g == "hospital pharmacy" | x$m4g == "hospital pharmacy" | x$m5g == "hospital pharmacy"| x$m6g == "hospital pharmacy" | x$m7g == "hospital pharmacy" | x$m88g == "hospital pharmacy" | x$m99g == "hospital pharmacy"] <- "public" x$drug.loc.pr[x$m1g == "public or street market" | x$m2g == "public or street market" | x$m3g == "public or street market"| x$m4g == "public or street market" | x$m5g == "public or street market" | x$m6g == "public or street market" | x$m7g == "public or street market" | x$m88g == "public or street market" | x$m99g == "public or street market" | x$m1g == "relative or friend" | x$m2g == "relative or friend" | x$m3g == "relative or friend"| x$m4g == "relative or friend" | x$m5g == "relative or friend" | x$m6g == "relative or friend" | x$m7g == "relative or friend" | x$m88g == "relative or friend" | x$m99g == "relative or friend" | x$m1g == "clinic" | x$m2g == "clinic" | x$m3g == "clinic" | x$m4g == "clinic" | x$m5g == "clinic"| x$m6g == "clinic" | x$m7g == "clinic" | x$m88g == "clinic" | x$m99g == "clinic" | x$m1g == "private pharmacy" | x$m2g == "private pharmacy" | x$m3g == "private pharmacy" | x$m4g == "private pharmacy" | x$m5g == "private pharmacy"| x$m6g == "private pharmacy" | x$m7g == "private pharmacy" | x$m88g == "private pharmacy" | x$m99g == "private pharmacy"] <- "private" x$drug.loc.pu[x$m1g == NA | x$m2g == NA | x$m3g == NA | x$m4g == NA | x$m5g == NA| x$m6g == NA | x$m7g == NA | x$m88g == NA | x$m99g == NA] <- NA x$drug.loc.pr[x$m1g == NA | x$m2g == NA | x$m3g == NA | x$m4g == NA | x$m5g == NA| x$m6g == NA | x$m7g == NA | x$m88g == NA | x$m99g == NA] <- NA x$location[x$loc == "Town" | x$loc == "Country side"] <- "Rural" x$location[x$loc == "City" | x$loc == "County city" | x$loc == "District city"] <- "Urban" ## 15. Mean Annual Incremental Drug Costs x$mean.med1c[x$met == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Urban"] <- 1384 x$mean.med1c[is.na(x$mean.med1)] <- 0 x$mean.med2c[x$su == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Urban"] <- 1272 x$mean.med2c[is.na(x$mean.med2)] <- 0 x$mean.med3c[x$acar == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Urban"] <- 4613 x$mean.med3c[is.na(x$mean.med3)] <- 0 x$mean.med4c[x$ins == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Urban"] <- 4814 x$mean.med4c[is.na(x$mean.med4)] <- 0 x$mean.med5c[x$other.gllow == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Urban"] <- 1962 x$mean.med5c[is.na(x$mean.med5)] <- 0 x$mean.med6c[x$any.lipid == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Urban"] <- 1460 x$mean.med6c[is.na(x$mean.med6)] <- 0 x$mean.med7c[x$any.bp == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Urban"] <- 607 x$mean.med7c[is.na(x$mean.med7)] <- 0 x$mean.med8c[x$any.anticoag == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Urban"] <- 396 x$mean.med8c[is.na(x$mean.med8)] <- 0 x$mean.med9c[x$other.nondm == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Urban"] <- 1514 x$mean.med9c[is.na(x$mean.med9)] <- 0 x$mean.med10c[x$met == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Rural"] <- 651 x$mean.med10c[is.na(x$mean.med10)] <- 0 x$mean.med11c[x$su == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Rural"] <- 786 x$mean.med11c[is.na(x$mean.med11)] <- 0 x$mean.med12c[x$acar == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Rural"] <- 1582 x$mean.med12c[is.na(x$mean.med12)] <- 0 x$mean.med13c[x$ins == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Rural"] <- 2419 x$mean.med13c[is.na(x$mean.med13)] <- 0 x$mean.med14c[x$other.gllow == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Rural"] <- 767 x$mean.med14c[is.na(x$mean.med14)] <- 0 x$mean.med15c[x$any.lipid == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Rural"] <- 1304 x$mean.med15c[is.na(x$mean.med15)] <- 0 x$mean.med16c[x$any.bp == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Rural"] <- 313 x$mean.med16c[is.na(x$mean.med16)] <- 0 x$mean.med17c[x$any.anticoag == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Rural"] <- 174 x$mean.med17c[is.na(x$mean.med17)] <- 0 x$mean.med18c[x$other.nondm == "Yes" & x$drug.loc.pr == "private" & x$case == "Diabetes" & x$location == "Rural"] <- 376 x$mean.med18c[is.na(x$mean.med18)] <- 0 x$mean.med19c[x$met == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Urban"] <- 836 x$mean.med19c[is.na(x$mean.med19)] <- 0 x$mean.med20c[x$su == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Urban"] <- 1558 x$mean.med20c[is.na(x$mean.med20)] <- 0 x$mean.med21c[x$acar == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Urban"] <- 2622 x$mean.med21c[is.na(x$mean.med21)] <- 0 x$mean.med22c[x$ins == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Urban"] <- 4046 x$mean.med22c[is.na(x$mean.med22)] <- 0 x$mean.med23c[x$other.gllow == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Urban"] <- 3020 x$mean.med23c[is.na(x$mean.med23)] <- 0 x$mean.med24c[x$any.lipid == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Urban"] <- 2521 x$mean.med24c[is.na(x$mean.med24)] <- 0 x$mean.med25c[x$any.bp == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Urban"] <- 1160 x$mean.med25c[is.na(x$mean.med25)] <- 0 x$mean.med26c[x$any.anticoag == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Urban"] <- 562 x$mean.med26c[is.na(x$mean.med26)] <- 0 x$mean.med27c[x$other.nondm == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Urban"] <- 1313 x$mean.med27c[is.na(x$mean.med27)] <- 0 x$mean.med28c[x$met == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Rural"] <- 933 x$mean.med28c[is.na(x$mean.med28)] <- 0 x$mean.med29c[x$su == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Rural"] <- 1172 x$mean.med29c[is.na(x$mean.med29)] <- 0 x$mean.med30c[x$acar == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Rural"] <- 2506 x$mean.med30c[is.na(x$mean.med30)] <- 0 x$mean.med31c[x$ins == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Rural"] <- 9451 x$mean.med31c[is.na(x$mean.med31)] <- 0 x$mean.med32c[x$other.gllow == "Yes" &x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Rural"] <- 2234 x$mean.med32c[is.na(x$mean.med32)] <- 0 x$mean.med33c[x$any.lipid == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Rural"] <- 5697 x$mean.med33c[is.na(x$mean.med33)] <- 0 x$mean.med34c[x$any.bp == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Rural"] <- 737 x$mean.med34c[is.na(x$mean.med34)] <- 0 x$mean.med35c[x$any.anticoag == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Rural"] <- 415 x$mean.med35c[is.na(x$mean.med35)] <- 0 x$mean.med36c[x$other.nondm == "Yes" & x$drug.loc.pu == "public" & x$case == "Diabetes" & x$location == "Rural"] <- 985 x$mean.med36c[is.na(x$mean.med36)] <- 0 x$mean.med37c[x$any.lipid == "Yes" & x$drug.loc.pr == "private" & x$case == "No Diabetes" & x$location == "Urban"] <- 172 x$mean.med37c[is.na(x$mean.med37)] <- 0 x$mean.med38c[x$any.bp == "Yes" & x$drug.loc.pr == "private" & x$case == "No Diabetes" & x$location == "Urban"] <- 469 x$mean.med38c[is.na(x$mean.med38)] <- 0 x$mean.med39c[x$any.anticoag == "Yes" & x$drug.loc.pr == "private" & x$case == "No Diabetes" & x$location == "Urban"] <- 156 x$mean.med39c[is.na(x$mean.med39)] <- 0 x$mean.med40c[x$other.nondm == "Yes" & x$drug.loc.pr == "private" & x$case == "No Diabetes" & x$location == "Urban"] <- 2004 x$mean.med40c[is.na(x$mean.med40)] <- 0 x$mean.med41c[x$any.lipid == "Yes" & x$drug.loc.pr == "private" & x$case == "No Diabetes" & x$location == "Rural"] <- 4198 x$mean.med41c[is.na(x$mean.med41)] <- 0 x$mean.med42c[x$any.bp == "Yes" & x$drug.loc.pr == "private" & x$case == "No Diabetes" & x$location == "Rural"] <- 1681 x$mean.med42c[is.na(x$mean.med42)] <- 0 x$mean.med43c[x$any.anticoag == "Yes" & x$drug.loc.pr == "private" & x$case == "No Diabetes" & x$location == "Rural"] <- 1187 x$mean.med43c[is.na(x$mean.med43)] <- 0 x$mean.med44c[x$other.nondm == "Yes" & x$drug.loc.pr == "private" & x$case == "No Diabetes" & x$location == "Rural"] <- 2086 x$mean.med44c[is.na(x$mean.med44)] <- 0 x$mean.med45c[x$any.lipid == "Yes" & x$drug.loc.pu == "public" & x$case == "No Diabetes" & x$location == "Urban"] <- 1536 x$mean.med45c[is.na(x$mean.med45)] <- 0 x$mean.med46c[x$any.bp == "Yes" & x$drug.loc.pu == "public" & x$case == "No Diabetes" & x$location == "Urban"] <- 1509 x$mean.med46c[is.na(x$mean.med46)] <- 0 x$mean.med47c[x$any.anticoag == "Yes" & x$drug.loc.pu == "public" & x$case == "No Diabetes" & x$location == "Urban"] <- 645 x$mean.med47c[is.na(x$mean.med47)] <- 0 x$mean.med48c[x$other.nondm == "Yes" & x$drug.loc.pu == "public" & x$case == "No Diabetes" & x$location == "Urban"] <- 1143 x$mean.med48c[is.na(x$mean.med48)] <- 0 x$mean.med49c[x$any.lipid == "Yes" & x$drug.loc.pu == "public" & x$case == "No Diabetes" & x$location == "Rural"] <- 1825 x$mean.med49c[is.na(x$mean.med49)] <- 0 x$mean.med50c[x$any.bp == "Yes" & x$drug.loc.pu == "public" & x$case == "No Diabetes" & x$location == "Rural"] <- 701 x$mean.med50c[is.na(x$mean.med50)] <- 0 x$mean.med51c[x$any.anticoag == "Yes" & x$drug.loc.pu == "public" & x$case == "No Diabetes" & x$location == "Rural"] <- 741 x$mean.med51c[is.na(x$mean.med51)] <- 0 x$mean.med52c[x$other.nondm == "Yes" & x$drug.loc.pu == "public" & x$case == "No Diabetes" & x$location == "Rural"] <- 1156 x$mean.med52c[is.na(x$mean.med52)] <- 0 x$mean.med.tot.pu <- x$mean.med19c+x$mean.med20c+x$mean.med21c+x$mean.med22c+x$mean.med23c+ x$mean.med24c+x$mean.med25c+x$mean.med26c+x$mean.med27c+x$mean.med28c+x$mean.med29c+x$mean.med30c+x$mean.med31c+ x$mean.med32c+x$mean.med33c+x$mean.med34c+x$mean.med35c+x$mean.med36c+x$mean.med45c+ x$mean.med46c+x$mean.med47c+x$mean.med48c+x$mean.med49c+x$mean.med50c+x$mean.med51c+x$mean.med52c x$mean.med.tot.pr <- x$mean.med1c+x$mean.med2c+x$mean.med3c+x$mean.med4c+x$mean.med5c+x$mean.med6c+x$mean.med7c+ x$mean.med8c+x$mean.med9c+x$mean.med10c+x$mean.med11c+x$mean.med12c+x$mean.med13c+x$mean.med14c+x$mean.med15c+ x$mean.med16c+x$mean.med17c+x$mean.med18c+x$mean.med37c+x$mean.med38c+ x$mean.med39c+x$mean.med40c+x$mean.med41c+x$mean.med42c+x$mean.med43c+x$mean.med44c x$mean.med.tot <- x$mean.med.tot.pu + x$mean.med.tot.pr ## 16. Glucose Monitoring ##Home Glucose Monitoring x$own.bg.12 <- as.numeric(x$own.bg.12) x$own.bg.24 <- as.numeric(x$own.bg.24) x$own.bg.52 <- as.numeric(x$own.bg.52) x$hm.less.wk <- "No" x$hm.less.wk[x$own.bg.12 > 0] <- "Yes" x$hm.day <- "No" x$hm.day[x$own.bg.24 > 0] <- "Yes" x$hm.less.day <- "No" x$hm.less.day[x$own.bg.52 > 0] <- "Yes" x$hm.any <- "No" x$hm.any[x$own.bg.52 > 0 | x$own.bg.12 > 0 | x$own.bg.24 > 0] <- "Yes" ##Professional GLUCOSE Monitoring x$hp.bg.24 <- as.numeric(x$hp.bg.24) x$hp.bg.12 <- as.numeric(x$hp.bg.12) x$hp.bg.52 <- as.numeric(x$hp.bg.52) x$hp.bg.any <- "No" x$hp.bg.any[x$hp.bg.24 > 0 | x$hp.bg.12 > 0 | x$hp.bg.52 > 0] <- "Yes" ##expenditures out of pocket on monitoring x$oop.days.bg <- (365 * x$dm41) * x$bg.cost x$oop.weeks.bg <- (52 * x$dm42) * x$bg.cost x$oop.year.bg <- (12 * x$dm43) * x$bg.cost bg <- x[!is.na(x$oop.days.bg) | !is.na(x$oop.weeks.bg) | !is.na(x$oop.year.bg), c("ID", "oop.days.bg", "oop.weeks.bg", "oop.year.bg")] bg$oop.days.bg[is.na(bg$oop.days.bg)] <- 0 bg$oop.weeks.bg[is.na(bg$oop.weeks.bg)] <- 0 bg$oop.year.bg[is.na(bg$oop.year.bg)] <- 0 bg$oop.bg.yr <- bg$oop.days.bg + bg$oop.weeks.bg + bg$oop.year.bg bg <- bg[c("ID", "oop.bg.yr")] num.rows <- nrow(x) x <- merge(bg, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) x$oop.bg.90 <- x$oop.bg.yr/4 ## expenditures out of pocket on strips x$oop.days <- (365 / (x$strips / x$own.bg.24)) * x$paid.strips x$oop.weeks <- (52 / (x$strips / x$own.bg.52)) * x$paid.strips x$oop.year <- (12 / (x$strips / x$own.bg.12)) * x$paid.strips strips <- x[!is.na(x$oop.days) | !is.na(x$oop.weeks) | !is.na(x$oop.year), c("ID", "oop.days", "oop.weeks", "oop.year")] strips$oop.days[is.na(strips$oop.days)] <- 0 strips$oop.weeks[is.na(strips$oop.weeks)] <- 0 strips$oop.year[is.na(strips$oop.year)] <- 0 strips$oop.strips.yr <- strips$oop.days + strips$oop.weeks + strips$oop.year strips <- strips[c("ID", "oop.strips.yr")] num.rows <- nrow(x) x <- merge(strips, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) x$oop.strips.90 <- x$oop.strips.yr/4 ## annual travel costs to the hospital trav <- x[!is.na(x$tcad) | !is.na(x$hosp.ad)| !is.na(x$tcew) | !is.na(x$hosp.ew)| !is.na(x$tcop) | !is.na(x$hosp.op), c("ID", "tcad", "hosp.ad", "tcew", "hosp.ew", "tcop", "hosp.op")] trav$tcad[is.na(trav$tcad)] <- 0 trav$tcew[is.na(trav$tcew)] <- 0 trav$tcop[is.na(trav$tcop)] <- 0 trav$hosp.ad[is.na(trav$hosp.ad)] <- 0 trav$hosp.ew[is.na(trav$hosp.ew)] <- 0 trav$hosp.op[is.na(trav$hosp.op)] <- 0 trav$h.travel.yr <- ((trav$tcad * trav$hosp.ad) + (trav$tcew * trav$hosp.ew) + (trav$tcop * trav$hosp.op))* 2 * 4 trav <- trav[c("ID", "h.travel.yr")] num.rows <- nrow(x) x <- merge(trav, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) ## 17. annual travel costs to non-hospital services n.tr <- x[!is.na(x$wmtc) | !is.na(x$wm.visit)| !is.na(x$thtc) | !is.na(x$th.visit)| !is.na(x$tmtc) | !is.na(x$tm.visit)| !is.na(x$phtc) | !is.na(x$ph.visit)| !is.na(x$chtc) | !is.na(x$ch.visit), c("ID", "wmtc", "wm.visit", "thtc", "th.visit", "tmtc", "tm.visit", "phtc", "ph.visit", "chtc", "ch.visit")] n.tr$wmtc[is.na(n.tr$wmtc)] <- 0 n.tr$tmtc[is.na(n.tr$tmtc)] <- 0 n.tr$thtc[is.na(n.tr$thtc)] <- 0 n.tr$phtc[is.na(n.tr$phtc)] <- 0 n.tr$chtc[is.na(n.tr$chtc)] <- 0 n.tr$wm.visit[is.na(n.tr$wm.visit)] <- 0 n.tr$tm.visit[is.na(n.tr$tm.visit)] <- 0 n.tr$th.visit[is.na(n.tr$th.visit)] <- 0 n.tr$ph.visit[is.na(n.tr$ph.visit)] <- 0 n.tr$ch.visit[is.na(n.tr$ch.visit)] <- 0 n.tr$n.travel.90 <- n.tr$wmtc + n.tr$thtc + n.tr$tmtc + n.tr$chtc n.tr <- n.tr[c("ID", "n.travel.90")] num.rows <- nrow(x) x <- merge(n.tr, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) x$n.travel.yr <- x$n.travel.90 * 2 * 4 ## 18. costs of food and boarding f <- x[!is.na(x$pyadb) | !is.na(x$hosp.ad)| !is.na(x$pyewb) | !is.na(x$hosp.ew)| !is.na(x$pycb) | !is.na(x$hosp.op), c("ID", "pyadb", "hosp.ad", "pyewb", "hosp.ew", "pycb", "hosp.op")] f$pyadb[is.na(f$pyadb)] <- 0 f$pyewb[is.na(f$pyewb)] <- 0 f$pypcb[is.na(f$pycb)] <- 0 f$hosp.ad[is.na(f$hosp.ad)] <- 0 f$hosp.ew[is.na(f$hosp.ew)] <- 0 f$hosp.op[is.na(f$hosp.op)] <- 0 f$food.90 <- (f$pyadb * f$hosp.ad) + (f$pyewb * f$hosp.ew) + (f$pycb * f$hosp.op) f <- f[c("ID", "food.90")] num.rows <- nrow(x) x <- merge(x, f, by = "ID", all.x = TRUE) stopifnot(nrow(x) == num.rows) x$food.yr <- x$food.90 * 4 ## pay for person to care x$pay.mo <- x$pay x$pay.yr <- x$pay.mo * 12 ## 19. annual total travel time in days both ways non hospital ti <- x[!is.na(x$wmtt) | !is.na(x$wm.visit) | !is.na(x$thtt) | !is.na(x$th.visit) | !is.na(x$phtt) | !is.na(x$ph.visit) | !is.na(x$tmtt) | !is.na(x$tm.visit) | !is.na(x$chtt) | !is.na(x$ch.visit), c("ID", "wmtt", "wm.visit", "thtt", "th.visit", "phtt", "ph.visit", "tmtt", "tm.visit", "chtt", "ch.visit")] ti$wmtt[is.na(ti$wmtt)] <- 0 ti$thtt[is.na(ti$thtt)] <- 0 ti$phtt[is.na(ti$phtt)] <- 0 ti$tmtt[is.na(ti$tmtt)] <- 0 ti$chtt[is.na(ti$chtt)] <- 0 ti$ph.visit[is.na(ti$ph.visit)] <- 0 ti$wm.visit[is.na(ti$wm.visit)] <- 0 ti$tm.visit[is.na(ti$tm.visit)] <- 0 ti$ch.visit[is.na(ti$ch.visit)] <- 0 ti$th.visit[is.na(ti$th.visit)] <- 0 ti$n.time.90 <- ((ti$wmtt * ti$wm.visit) + (ti$tmtt * ti$tm.visit) + (ti$thtt * ti$th.visit) + (ti$phtt * ti$ph.visit) + (ti$chtt * ti$ch.visit)) * 2 / 8 ti <- ti[c("ID", "n.time.90")] num.rows <- nrow(x) x <- merge(ti, x, by = "ID", all.y = TRUE) stopifnot(nrow(x) == num.rows) x$n.time.yr <- x$n.time.90 * 4 ## 20. annual total travel time in days both ways hospital visits h <- x[!is.na(x$trad) | !is.na(x$hosp.ad) | !is.na(x$trew) | !is.na(x$hosp.ew) | !is.na(x$trop) | !is.na(x$hosp.op) | !is.na(x$pead) | !is.na(x$peew) | !is.na(x$peop), c("ID", "trad", "hosp.ad", "trew", "hosp.ew", "trop", "hosp.op", "pead", "peew", "peop")] h$trad[is.na(h$trad)] <- 0 h$trew[is.na(h$trew)] <- 0 h$trop[is.na(h$trop)] <- 0 h$pead[is.na(h$pead)] <- 0 h$peew[is.na(h$peew)] <- 0 h$peop[is.na(h$peop)] <- 0 h$hosp.ad[is.na(h$hosp.ad)] <- 0 h$hosp.ew[is.na(h$hosp.ew)] <- 0 h$hosp.op[is.na(h$hosp.op)] <- 0 h$h.time.90 <- ((h$trad * h$hosp.ad) + (h$trew * h$hosp.ew) + (h$trop * h$hosp.op) + (h$trad * h$hosp.ad * h$pead) + (h$trew * h$hosp.ew * h$peew) + (h$trop * h$hosp.op * h$peop)) * 2 / 8 h <- h[c("ID", "h.time.90")] num.rows <- nrow(x) x <- merge(x, h, by = "ID", all.x = TRUE) stopifnot(nrow(x) == num.rows) x$h.time.yr <- x$h.time.90 * 4 tim <- numeric(nrow(x)) for (i in 1:nrow(x)) { tim[i] <- sum(x[i, "n.time.90"], x[i, "h.time.90"], na.rm = TRUE) } x$tot.time.travel.90 <- tim x$tot.time.travel.90[is.na(x$n.time.90) & is.na(x$h.time.90)] <- NA tiy <- numeric(nrow(x)) for (i in 1:nrow(x)) { tiy[i] <- sum(x[i, "n.time.yr"], x[i, "h.time.yr"], na.rm = TRUE) } x$tot.time.travel.yr <- tiy x$tot.time.travel.yr[is.na(x$n.time.yr) & is.na(x$h.time.yr)] <- NA ## 21. Site names x$site <- as.character(x$site) x$site[x$site == "01" | x$site == "03" | x$site == "04"] <- "Beijing" x$site[x$site == "06"] <- "liaoning" x$site[x$site == "09"] <- "Shandong" x$site[x$site == "08"] <- "Shanxi" x$site[x$site == "10"] <- "Shanghai" x$site[x$site == "12"] <- "Hunan" x$site[x$site == "14"] <- "Fujian" x$site[x$site == "15"] <- "Sichuan" x$site[x$site == "16"] <- "Shaanxi" x$site[x$site == "17"] <- "Xinjiang" x$site[x$site == "05" | x$site == "60"] <- NA ## 22. Urban/Rural location break-down x$location[x$loc == "Town" | x$loc == "Country side"] <- "Rural" x$location[x$loc == "City" | x$loc == "County city" | x$loc == "District city"] <- "Urban" ## 23. Duration DM x$dur.gp[x$dm.yrs == "0"] <- "0 to 2 yrs" x$dur.gp[x$dm.yrs == "1"] <- "0 to 2 yrs" x$dur.gp[x$dm.yrs == "2"] <- "0 to 2 yrs" x$dur.gp[x$dm.yrs == "3"] <- "3 to 5 yrs" x$dur.gp[x$dm.yrs == "4"] <- "3 to 5 yrs" x$dur.gp[x$dm.yrs == "5"] <- "3 to 5 yrs" x$dur.gp[x$dm.yrs == "6"] <- "6 to 10 yrs" x$dur.gp[x$dm.yrs == "7"] <- "6 to 10 yrs" x$dur.gp[x$dm.yrs == "8"] <- "6 to 10 yrs" x$dur.gp[x$dm.yrs == "9"] <- "6 to 10 yrs" x$dur.gp[x$dm.yrs == "10"] <- "6 to 10 yrs" x$dur.gp[x$dm.yrs == "11"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "12"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "13"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "14"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "15"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "16"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "17"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "18"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "19"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "20"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "21"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "22"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "23"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "24"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "25"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "26"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "27"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "29"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "30"] <- "more than 10 yrs" x$dur.gp[x$dm.yrs == "40"] <- "more than 10 yrs" ## 24. Age Brackets x$age.b[x$age > 0 & x$age < 40] <- "0 to 39 yrs." x$age.b[x$age >= 40 & x$age < 50] <- "40 to 49 yrs." x$age.b[x$age >= 50 & x$age < 60] <- "50 to 59 yrs." x$age.b[x$age >= 60 & x$age < 70] <- "60 to 69 yrs." x$age.b[x$age >= 70] <- "70+ yrs." ## 25. Creation of Medication specific dataset ##Create Duplicate X Files x1 <- x x1$copy <- as.character(x1$copy) x1$copy[x1$copy == "a"] <- "b" x2 <- x x2$copy <- as.character(x2$copy) x2$copy[x2$copy == "a"] <- "c" x3 <- x x3$copy <- as.character(x3$copy) x3$copy[x3$copy == "a"] <- "d" x4 <- x x4$copy <- as.character(x4$copy) x4$copy[x4$copy == "a"] <- "e" x5 <- x x5$copy <- as.character(x5$copy) x5$copy[x5$copy == "a"] <- "f" x6 <- x x6$copy <- as.character(x6$copy) x6$copy[x6$copy == "a"] <- "g" x7 <- x x7$copy <- as.character(x7$copy) x7$copy[x7$copy == "a"] <- "h" x8 <- x x8$copy <- as.character(x8$copy) x8$copy[x8$copy == "a"] <- "i" ##Append Duplicate Files x.final <- rbind(x, x1, x2, x3, x4, x5, x6, x7, x8) ##Create new columns for analysis x.final$m1a <- as.character(x.final$m1a) m1a <- x.final$m1a x.final$mxa[x.final$copy == "a"] <- m1a x.final$m1b <- as.integer(x.final$m1b) m1b <- x.final$m1b x.final$mxb[x.final$copy == "a"] <- m1b m1c <- x.final$m1c x.final$mxc[x.final$copy == "a"] <- m1c m1d <- x.final$m1d x.final$mxd[x.final$copy == "a"] <- m1d x.final$m1e <- as.character(x.final$m1e) m1e <- x.final$m1e x.final$m1e[x.final$m1e == "0"] <- NA x.final$mxe[x.final$copy == "a"] <- m1e x.final$m1f <- as.character(x.final$m1f) m1f <- x.final$m1f x.final$mxf[x.final$copy == "a"] <- m1f x.final$m1g <- as.character(x.final$m1g) m1g <- x.final$m1g x.final$mxg[x.final$copy == "a"] <- m1g m1h <- x.final$m1h x.final$mxh[x.final$copy == "a"] <- m1h m1i <- x.final$m1i x.final$mxi[x.final$copy == "a"] <- m1i x.final$m2a <- as.character(x.final$m2a) m2a <- x.final$m2a x.final$mxa[x.final$copy == "b"] <- m2a m2b <- x.final$m2b x.final$mxb[x.final$copy == "b"] <- m2b m2c <- x.final$m2c x.final$mxc[x.final$copy == "b"] <- m2c m2d <- x.final$m2d x.final$mxd[x.final$copy == "b"] <- m2d x.final$m2e <- as.character(x.final$m2e) m2e <- x.final$m2e x.final$m2e[x.final$m2e == "0"] <- NA x.final$mxe[x.final$copy == "b"] <- m2e x.final$m2f <- as.character(x.final$m2f) m2f <- x.final$m2f x.final$mxf[x.final$copy == "b"] <- m2f x.final$m2g <- as.character(x.final$m2g) m2g <- x.final$m2g x.final$mxg[x.final$copy == "b"] <- m2g m2h <- x.final$m2h x.final$mxh[x.final$copy == "b"] <- m2h m2i <- x.final$m2i x.final$mxi[x.final$copy == "b"] <- m2i x.final$m3a <- as.character(x.final$m3a) m3a <- x.final$m3a x.final$mxa[x.final$copy == "c"] <- m3a x.final$m3b <- as.integer(x.final$m3b) m3b <- x.final$m3b x.final$mxb[x.final$copy == "c"] <- m3b m3c <- x.final$m3c x.final$mxc[x.final$copy == "c"] <- m3c m3d <- x.final$m3d x.final$mxd[x.final$copy == "c"] <- m3d x.final$m3e <- as.character(x.final$m3e) m3e <- x.final$m3e x.final$m3e[x.final$m3e == "0"] <- NA x.final$mxe[x.final$copy == "c"] <- m3e x.final$m3f <- as.character(x.final$m3f) m3f <- x.final$m3f x.final$mxf[x.final$copy == "c"] <- m3f x.final$m3g <- as.character(x.final$m3g) m3g <- x.final$m3g x.final$mxg[x.final$copy == "c"] <- m3g m3h <- x.final$m3h x.final$mxh[x.final$copy == "c"] <- m3h m3i <- x.final$m3i x.final$mxi[x.final$copy == "c"] <- m3i x.final$m4a <- as.character(x.final$m4a) m4a <- x.final$m4a x.final$mxa[x.final$copy == "d"] <- m4a x.final$m4b <- as.integer(x.final$m4b) m4b <- x.final$m4b x.final$mxb[x.final$copy == "d"] <- m4b m4c <- x.final$m4c x.final$mxc[x.final$copy == "d"] <- m4c m4d <- x.final$m4d x.final$mxd[x.final$copy == "d"] <- m4d x.final$m4e <- as.character(x.final$m4e) m4e <- x.final$m4e x.final$m4e[x.final$m4e == "0"] <- NA x.final$mxe[x.final$copy == "d"] <- m4e x.final$m4f <- as.character(x.final$m4f) m4f <- x.final$m4f x.final$mxf[x.final$copy == "d"] <- m4f x.final$m4g <- as.character(x.final$m4g) m4g <- x.final$m4g x.final$mxg[x.final$copy == "d"] <- m4g m4h <- x.final$m4h x.final$mxh[x.final$copy == "d"] <- m4h m4i <- x.final$m4i x.final$mxi[x.final$copy == "d"] <- m4i x.final$m5a <- as.character(x.final$m5a) m5a <- x.final$m5a x.final$mxa[x.final$copy == "e"] <- m5a m5b <- x.final$m5b x.final$mxb[x.final$copy == "e"] <- m5b m5c <- x.final$m5c x.final$mxc[x.final$copy == "e"] <- m5c m5d <- x.final$m5d x.final$mxd[x.final$copy == "e"] <- m5d x.final$m5e <- as.character(x.final$m5e) m5e <- x.final$m5e x.final$m5e[x.final$m5e == "0"] <- NA x.final$mxe[x.final$copy == "e"] <- m5e x.final$m5f <- as.character(x.final$m5f) m5f <- x.final$m5f x.final$mxf[x.final$copy == "e"] <- m5f x.final$m5g <- as.character(x.final$m5g) m5g <- x.final$m5g x.final$mxg[x.final$copy == "e"] <- m5g m5h <- x.final$m5h x.final$mxh[x.final$copy == "e"] <- m5h m5i <- x.final$m5i x.final$mxi[x.final$copy == "e"] <- m5i x.final$m6a <- as.character(x.final$m6a) m6a <- x.final$m6a x.final$mxa[x.final$copy == "f"] <- m6a m6b <- x.final$m6b x.final$mxb[x.final$copy == "f"] <- m6b m6c <- x.final$m6c x.final$mxc[x.final$copy == "f"] <- m6c m6d <- x.final$m6d x.final$mxd[x.final$copy == "f"] <- m6d x.final$m6e <- as.character(x.final$m6e) m6e <- x.final$m6e x.final$m6e[x.final$m6e == "0"] <- NA x.final$mxe[x.final$copy == "f"] <- m6e x.final$m6f <- as.character(x.final$m6f) m6f <- x.final$m6f x.final$mxf[x.final$copy == "f"] <- m6f x.final$m6g <- as.character(x.final$m6g) m6g <- x.final$m6g x.final$mxg[x.final$copy == "f"] <- m6g m6h <- x.final$m6h x.final$mxh[x.final$copy == "f"] <- m6h m6i <- x.final$m6i x.final$mxi[x.final$copy == "f"] <- m6i x.final$m7a <- as.character(x.final$m7a) m7a <- x.final$m7a x.final$mxa[x.final$copy == "g"] <- m7a m7b <- x.final$m7b x.final$mxb[x.final$copy == "g"] <- m7b m7c <- x.final$m7c x.final$mxc[x.final$copy == "g"] <- m7c m7d <- x.final$m7d x.final$mxd[x.final$copy == "g"] <- m7d x.final$m7e <- as.character(x.final$m7e) m7e <- x.final$m7e x.final$m7e[x.final$m7e == "0"] <- NA x.final$mxe[x.final$copy == "g"] <- m7e x.final$m7f <- as.character(x.final$m7f) m7f <- x.final$m7f x.final$mxf[x.final$copy == "g"] <- m7f x.final$m7g <- as.character(x.final$m7g) m7g <- x.final$m7g x.final$mxg[x.final$copy == "g"] <- m7g m7h <- x.final$m7h x.final$mxh[x.final$copy == "g"] <- m7h m7i <- x.final$m7i x.final$mxi[x.final$copy == "g"] <- m7i x.final$m88a <- as.character(x.final$m88a) m88a <- x.final$m88a x.final$mxa[x.final$copy == "h"] <- m88a m88b <- x.final$m88b x.final$mxb[x.final$copy == "h"] <- m88b m88c <- x.final$m88c x.final$mxc[x.final$copy == "h"] <- m88c m88d <- x.final$m88d x.final$mxd[x.final$copy == "h"] <- m88d x.final$m88e <- as.character(x.final$m88e) m88e <- x.final$m88e x.final$m88e[x.final$m88e == "0"] <- NA x.final$mxe[x.final$copy == "h"] <- m88e x.final$m88f <- as.character(x.final$m88f) m88f <- x.final$m88f x.final$mxf[x.final$copy == "h"] <- m88f x.final$m88g <- as.character(x.final$m88g) m88g <- x.final$m88g x.final$mxg[x.final$copy == "h"] <- m88g m88h <- x.final$m88h x.final$mxh[x.final$copy == "h"] <- m88h m88i <- x.final$m88i x.final$mxi[x.final$copy == "h"] <- m88i x.final$m99a <- as.character(x.final$m99a) m99a <- x.final$m99a x.final$mxa[x.final$copy == "i"] <- m99a m99b <- x.final$m99b x.final$mxb[x.final$copy == "i"] <- m99b m99c <- x.final$m99c x.final$mxc[x.final$copy == "i"] <- m99c m99d <- x.final$m99d x.final$mxd[x.final$copy == "i"] <- m99d x.final$m99e <- as.character(x.final$m99e) m99e <- x.final$m99e x.final$m99e[x.final$m99e == "0"] <- NA x.final$mxe[x.final$copy == "i"] <- m99e x.final$m99f <- as.character(x.final$m99f) m99f <- x.final$m99f x.final$mxf[x.final$copy == "i"] <- m99f x.final$m99g <- as.character(x.final$m99g) m99g <- x.final$m99g x.final$mxg[x.final$copy == "i"] <- m99g m99h <- x.final$m99h x.final$mxh[x.final$copy == "i"] <- m99h m99i <- x.final$m99i x.final$mxi[x.final$copy == "i"] <- m99i ##Delete blank rows for meds x.final$mxa[x.final$mxa == ""] <- NA x.final <- x.final[!is.na(x.final$mxa),] x.f <- x.final ##Meds Dosing and Pricing (m1c - m99i) x.f$mxi1 <- x.f$mxi x.f$mxi1[x.f$mxa == "acar" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "ace" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "alpha" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "anal" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "antibiotic" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "arb" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "asp" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "bb" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "Ca" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "ccb" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "clopid" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "co" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "combin" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "diur" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "fibrate" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "gastric" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "ginide" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "herb" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "herbb" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "herbd" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "met" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "other" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "psycho" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "reserpine" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "statin" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "su" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "tzd" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "vit" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "warf" & x.f$mxi1 > 300] <- NA x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 1] <- 100 x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 2] <- 200 x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 3] <- 300 x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 4] <- 400 x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 5] <- 500 x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 6] <- 600 x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 7] <- 700 x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 8] <- 800 x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 9] <- 900 x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 10] <- 1000 x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 14] <- NA x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 60] <- NA x.f$mxi1[x.f$mxa == "insulin" & x.f$mxi1 == 30] <- NA x.f$mxi1[x.f$mxi1 < 10] <- NA x.f$mxc1[x.f$mxc == 1] <- 1 x.f$mxc1[x.f$mxc == 2] <- 2 x.f$mxc1[x.f$mxc == 3] <- 3 x.f$mxc1[x.f$mxc == 4] <- 4 x.f$mxc1[x.f$mxc == 5] <- 5 x.f$mxc1[x.f$mxc == 6] <- 6 x.f$mxc1[x.f$mxc == 7] <- 7 x.f$mxc1[x.f$mxc == 8] <- 8 x.f$mxc1[x.f$mxc == 9] <- 9 x.f$mxd1[x.f$mxd == 1] <- 1 x.f$mxd1[x.f$mxd == 2] <- 2 x.f$mxd1[x.f$mxd == 3] <- 3 x.f$mxd1[x.f$mxd == 4] <- 4 x.f$mxd1[x.f$mxd == 5] <- 5 x.f$mxd1[x.f$mxd == 6] <- 6 x.f$mxd1[x.f$mxd == 7] <- 7 x.f$mxd1[x.f$mxd == 8] <- 8 x.f$mxd1[x.f$mxd == 9] <- 9 x.f$mxc1[x.f$mxa == "insulin" & x.f$mxc > "3"] <- NA x.f$mxd1[x.f$mxa == "insulin" & x.f$mxd > "3"] <- NA x.f$mxh[x.f$mxh > 2000] <- NA x.f$mxg1 <- x.f$mxg x.f$mxg1[x.f$mxg == "public or street market" | x.f$mxg == "relative or friend"] <- "other" x.f$mxg1[x.f$mxg == "refused" | x.f$mxg == "Does Not Know"] <- NA x.f$mxg2 <- x.f$mxg1 x.f$mxg2[x.f$mxg1 == "clinic" | x.f$mxg1 == "hospital pharmacy"] <- NA x.f$mxa[x.f$mxa == "herb" | x.f$mxa == "herbb" | x.f$mxa == "herbd"] <- NA x.f <- x.f[!is.na(x.f$mxa),] x.f$mxe[x.f$mxe == 0] <- NA x.f$mxe[x.f$mxe == 1] <- 7 x.f$mxe[x.f$mxe == 2] <- 5 x.f$mxe[x.f$mxe == 3] <- 2 x.f$mxe[x.f$mxe == 4] <- .5 x.f$mxe <- as.numeric(x.f$mxe) ## 26. File for export (.CHINA_PERSON_DATA) ##Drug Payments y <- data.frame(ID=x.f$ID, sc=x.f$sc, case=x.f$case, location=x.f$location, dur.gp=x.f$dur.gp, age.b=x.f$age.b, hosp.ad=x.f$hosp.ad, hosp.op=x.f$hosp.op, hosp.ew=x.f$hosp.ew, mxa=x.f$mxa, mxb=x.f$mxb, mxc=x.f$mxc1, mxd=x.f$mxd1, mxe=x.f$mxe, mxf=x.f$mxf, mxg=x.f$mxg1, mxg1=x.f$mxg2, mxh=x.f$mxh, mxi=x.f$mxi1, tpyad=x.f$tpyad, tyop1=x.f$tyop1, wm90=x.f$wm90, wmco=x.f$wmco, ph90=x.f$ph90, phco=x.f$phco, ch90=x.f$ch90, chco=x.f$chco) ## 27. Drug Adherence y$adherence <- y$mxd / y$mxc y$adherence[y$adherence > 1] <- NA y$adherence.b[y$adherence == 0] <- "No Adherence" y$adherence.b[y$adherence > 0 & y$adherence < 1] <- "Partial Adherence" y$adherence.b[y$adherence == 1] <- "Full Adherence" ## 28. Drug Payments ##Days Supply y$mxb[y$mxb == 300] <- NA y$day.sup.ins <- y$mxi / y$mxb y$day.sup.ins[y$day.sup.ins == 0] <- NA y$day.sup <- y$mxi / y$mxc y$day.sup[y$day.sup == 0] <- NA ##Days Supply As Used y$day.sup.use <- ((y$mxi / y$mxd) / (y$mxe / 7)) y$day.sup.use[y$day.sup.use == 0] <- NA ##Cost per day as prescribed y$cost.day.pres.ins <- y$mxh / y$day.sup.ins y$cost.day.pres <- y$mxh / y$day.sup ##Cost per day as used y$cost.day.use <- y$mxh / y$day.sup.use ##Cost per month y$cost.mo.ins <- y$cost.day.pres.ins * 30 y$cost.mo <- y$cost.day.pres * 30 y$cost.mo.use <- y$cost.day.use * 30 ##Cost per year y$cost.yr.ins <- y$cost.day.pres.ins * 365 y$cost.yr <- y$cost.day.pres * 365 y$cost.yr.use <- y$cost.day.use * 365 ## 29. Drug Coding y$met <- "No" y$met[y$mxa == "met"] <- "Yes" y$su <- "No" y$su[y$mxa == "su"] <- "Yes" y$acar <- "No" y$acar[y$mxa == "acar"] <- "Yes" y$oral.agents <- "No" y$oral.agents[y$mxa == "su" | y$mxa == "met" | y$mxa == "acar" | y$mxa == "ginide" | y$mxa == "co"] <- "Yes" y$ins <- "No" y$ins[y$mxa == "insulin"] <- "Yes" y$other.dm <- "No" y$other.dm[y$mxa == "asp" | y$mxa == "clopid"| y$mxa == "warf" | y$mxa == "ace" | y$mxa == "arb" | y$mxa == "bb" | y$mxa == "ccb" | y$mxa == "diur" | y$mxa == "reserpine" | y$mxa == "combin" | y$mxa == "su" | y$mxa == "met" | y$mxa == "acar" | y$mxa == "ginide" | y$mxa == "statin" |y$mxa == "clonidine" | y$mxa == "co"] <- "Yes" y$other.gllow <- "No" y$other.gllow[y$mxa == "ginide" | y$mxa == "co"] <- "Yes" y$anticoag<- "No" y$anticoag[y$mxa == "asp" | y$mxa == "clopid"| y$mxa == "warf"] <- "Yes" y$bp <- "No" y$bp[y$mxa == "ace" | y$mxa == "arb" | y$mxa == "bb" | y$mxa == "ccb" | y$mxa == "diur" | y$mxa == "reserpine" | y$mxa == "combin" | y$mxa == "clonidine"] <- "Yes" y$lipid <- "No" y$lipid[y$mxa == "statin" | y$mxa == "niacin"| y$mxa == "fibrate"] <- "Yes" y$nondm <- "No" y$nondm[y$mxa == "other" | y$mxa == "anal" | y$mxa == "psycho" | y$mxa == "gastric" | y$mxa == "antibiotic"] <- "Yes" ## 30. Public/Private Pharmacies y$private <- "No" y$private[y$mxg == "private pharmacy" | y$mxa == "clinic" | y$mxg == "other" | y$mxa == "public or street market" | y$mxa == "relative or friend"] <- "Yes" y$public <- "No" y$public[y$mxg == "hospital pharmacy"] <- "Yes" ## 31. export files (.CHINA_PERSON_DATA, .CHINA_MEDS_DATA, .CHINA_CLEAN_RECODED_SOURCE) write.csv(x, file=paste("/Users/erinschneider/Desktop/IDFDataFiles/China/CHINA_PERSON_DATA.csv", sep="")) write.csv(tot, file=paste("/Users/erinschneider/Desktop/IDFDataFiles/China/CHINA_CLEAN_RECODED_SOURCE.csv", sep="")) write.csv(y, file=paste("/Users/erinschneider/Desktop/IDFDataFiles/China/CHINA_MEDS_DATA.csv", sep=""))