**Code of 0/1 data*** **Generate the data file with Table 8.2 book**** **gen var1=1,....,67, by hand save "C:\My Documents\655LDA\DataLDA\cross2x2.dta" rename var1 id gen trt1=1 replace trt1=0 in 35/67 gen trt2=0 replace trt2=1 in 34/67 gen per1=1 replace per1=0 if res1==0&trt1==1 replace per1=0 if res1==0&trt1==0 gen per2=1 replace per2=0 if res2==0&trt2==1 replace per2=0 if res2==0&trt2==0 save "C:\My Documents\655LDA\DataLDA\cross2x2.dta", replace reshape long trt res, i(id) j(visit) label var res "Response 1=normal" label var trt "TReatment 1=A" xi: xtgee res i.trt*i.visit, nolog f(bin) l(logit) corr(exch) xtgee res trt visit, nolog f(bin) l(logit) corr(ind) xtgee res trt visit, nolog f(bin) l(logit) corr(ind) robust ***TRansitional Model*** ***Look at the transitional probabilities first xttrans res dis log(79*83/17/21) ***A subject with an abnormal response at one time ***has a 21% chance og getting a normal test at the next time ***The log odds ratio for a normal response for two sequantial observations is 2.9** sort id by id: gen resl1=res[_n-1] logit res resl1 logit res resl1 trt, nolog **RE model ---See book pg 181*** **first, the marginal model xtlogit res trt visit, nolog pa **the RE model*** xtlogit res trt visit, nolog re outfile id visit trt res per using "C:\My Documents\655LDA\DataLDA\cross2x2SAS.txt" ***Now the SAS code*** data cross2x2; infile 'C:\My Documents\655LDA\DataLDA\cross2x2SAS.txt'; input id visit trt res per; run; proc genmod data=cross2x2; class id trt; model res=trt visit trt*visit/type3 error=bin link=logit; repeated subject=id/logor=exch; run; proc genmod data=cross2x2; class id trt; model res=trt visit/type3 error=bin link=logit; repeated subject=id/logor=exch; run; proc genmod data=cross2x2; class id trt; model res=trt visit /type3 error=bin link=logit; repeated subject=id/type=ind; run; title "Unstructured correlation" proc genmod data=cross2x2 descending; class id visit; model res=trt visit trt*visit/dist=bin link=logit; repeated subject=id/type=un corrw covb modelse within=visit; run; title "Exponential correlation" proc genmod data=cross2x2 descending; class id visit; model res=trt visit trt*visit/dist=bin link=logit; repeated subject=id/type=ar(1) corrw covb modelse within=visit; run; title "Exchangeable correlation" proc genmod data=cross2x2 descending; class id visit; model res=trt visit trt*visit/dist=bin link=logit; repeated subject=id/type=exch corrw covb modelse within=visit; run; *******Code for Bin/N data**** glm rel trt visit, f(bin tot) l(logit) nolog outfile visit trt gr tot rel using "C:\My Documents\655LDA\DataLDA\cross22SAS.txt" ***SAS code*** data cross22; infile 'C:\My Documents\655LDA\DataLDA\cross22SAS.txt'; input visit trt gr tot rel; run; proc genmod data=cross22; model rel/tot=trt visit /dist=bin link=logit; run; proc genmod data=cross22; class id trt; model res=trt visit trt*visit/type3 error=bin link=logit; repeated subject=id/logor=exch; run;