****pgm: logistic.do******** **log using "c:\stata\tutorial\logistic\logistic.log", replace** use "C:\myfiles\analysis_data.dta", clear ***create variable codes***** capture drop age gen age=1 if ridageyr >=20 & ridageyr <40 replace age=2 if ridageyr >=40 & ridageyr <60 replace age=3 if ridageyr >=60 & ridageyr <. capture drop hichol gen hichol =1 if lbxtc >=240 & lbxtc<. | bpq100d==1 replace hichol =0 if hichol !=1 & lbxtc !=. capture drop bmigrp gen bmigrp=1 if bmxbmi<25 replace bmigrp=2 if bmxbmi>=25 & bmxbmi <30 replace bmigrp=3 if bmxbmi>=30 & bmxbmi <. capture drop hyper gen hyper=1 if (bpxsar>=140 & bpxsar<. | bpxdar>=90 & bpxdar <.) | bpq050a==1 replace hyper=0 if hyper !=1 & (bpxsar !=. & bpxdar !=.) capture drop logtrig gen logtrig = log(lbxtr) ****format variables****** capture label drop agefmt label define agefmt 1 "20-39" label define agefmt 2 "40-59", add label define agefmt 3 "60+", add capture label drop chfmt label define chfmt 1 "high cholesterol" label define chfmt 0 "no high cholesterol", add capture label drop bmifmt label define bmifmt 1 "<25", label define bmifmt 2 "25-29", add label define bmifmt 3 "30+", add capture label drop bpfmt label define bpfmt 1 "hypertension" label define bpfmt 0 "no hypertension", add capture label drop sexfmt label define sexfmt 1 "male" label define sexfmt 2 "female", add label values age agefmt label values hichol chfmt label values bmigrp bmifmt label values hyper bpfmt label values riagendr sexfmt capture drop eligible gen eligible=1 if wtsaf4yr!=. & hyper!=. & riagendr!=. & age!=. & hichol!=. & bmigrp!=. & logtrig!=. & wtsaf4yr!=0 char riagendr [omit]2 char age [omit] 2 char bmigrp [omit] 2 char hichol [omit] 1 *****Run univariate logistic regression model******* svyset [w=wtmec4yr], psu(sdmvpsu) strata (sdmvstra) xi: svy, subpop (if eligible==1): logistic hyper i.riagendr xi: svy, subpop (if eligible==1): logistic hyper i.age xi: svy, subpop (if eligible==1): logistic hyper i.hichol xi: svy, subpop (if eligible==1): logistic hyper i.bmigrp svyset [w=wtsaf4yr], psu(sdmvpsu) strata (sdmvstra) xi: svy, subpop (if eligible==1): logistic hyper logtrig *****Run multiple logistic regression model***** svyset [w=wtsaf4yr], psu(sdmvpsu) strata (sdmvstra) xi: svy, subpop(if eligible==1): logistic hyper i.riagendr i.age i.hichol i.bmigrp logtrig count if hyper!=. & age!=. & riagendr!=. & hichol!=. & bmigrp!=. & logtrig!=. ***Or, produce the beta coefficents****** xi: svy, subpop(if eligible==1): logit hyper i.riagendr i.age i.hichol i.bmigrp logtrig count if hyper!=. & age!=. & riagendr!=. & hichol!=. & bmigrp!=. & logtrig!=. ***Or, produce the odds ratios using logit command****** xi: svy, subpop(if eligible==1): logit hyper i.riagendr i.age i.hichol i.bmigrp logtrig,or count if hyper!=. & age!=. & riagendr!=. & hichol!=. & bmigrp!=. & logtrig!=. ****test all coeffiecients in model together**** test ****test each coefficient in model separately*** test _Iage_1 = _Iage_3, nosvyadjust ***test _Iage_1 _Iage_3, nosvyadjust*** overall** test _Iriagendr_1, nosvyadjust test _Ihichol_0, nosvyadjust ****test _Ibmigrp_1 _Ibmigrp_3, nosvyadjust***overall** test _Ibmigrp_1 = _Ibmigrp_3, nosvyadjust test logtrig, nosvyadjust *****Produce percent with hypertension by select variables****** svyset [w=wtmec4yr], psu(sdmvpsu) strata (sdmvstra) svy, subpop (if eligible==1): tab hyper riagendr, row col pearson null wald count if hyper!=. & riagendr!=. svy, subpop (if eligible==1): tab hyper age, row col pearson null wald count if hyper!=. & age!=. svy, subpop (if eligible==1): tab hyper hichol, row col pearson null wald count if hyper!=. & hichol!=. svy, subpop (if eligible==1): tab hyper bmigrp, row col pearson null wald count if hyper!=. & bmigrp!=. ***log close***