Hi,

I am analysing the results of a trial & would like to compare the proportion of individuals successfully treated between arms, adjusting for baseline differences (gender & age category). An example of my data is below.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(group outcome gender age agecat) byte t
0 0 0 21 1 1
0 0 0 26 1 1
0 0 1 27 1 1
0 1 0 18 0 1
0 1 1 21 1 1
1 0 1 20 0 1
1 1 0 18 0 1
1 1 0 30 1 1
1 1 1 23 1 1
1 1 1 24 1 1
end
label var outcome "=1 if success" 
label var gender "=1 if female" 
label var agecat "=1 if age >=21"
A number of papers I have found in my field do this using Mantel Haenszel (M-H) proportion adjusted for the baseline stratum.

I used the cs command to obtain the risk ratio applying the M-H weight using the following code, but have struggled to get the M-H adjusted risk difference.
Code:
 cs outcome group, by(gender agecat)
If I use a user-specified weight, I could use the M-H weights generated in the risk ratio command & apply these to the risk difference formula - however it strikes me that if this was the appropriate method, Stata would make this easier to run, & potentially the internal or external weights method is more appropriate?

The code I used to generate M-H weights & run the cs risk difference command is as follows:
Code:
gen mhwgt=.
forvalues i=0/1 {
    forvalues x=0/1 {
    
        tab outcome group if agecat==`i' & gender==`x', matcell(A)
        replace mhwgt = (A[2,1] * (A[1,2]+A[2,2])) / ( A[1,1]+A[1,2]+A[2,1]+A[2,2]) if agecat==`i' & gender==`x'
}
}
cs outcome group, by(agecat gender) rd standard(mhwgt)
I am not very familiar with matrices, so this may not be the most straightforward way to generate the weights (if this is even an appropriate method).

Alternatively, I have considered using a different methodology, such as glm to fit a risk-difference model as in this post.
Code:
glm outcome group agecat gender, family(binomial) link(identity)
Or a logit model followed by margins.
Code:
logit outcome i.group agecat gender
margins group, pwcompare
Any advice on how to estimate the difference in response rate using M-H proportions and adjusting for baseline strata or whether an alternative methodology may be better would be very warmly received!

Best wishes,
Bryony