Hello,

I am trying to calculate the median difference between two variables. I have read about the somersd package and the cendif command by Newson, but the syntax of cendif is not clear to me.
For instance, using the example reported by Newson (2006), I did:

.use http://www.stata-press.com/data/r9/fuel, clear
.signrank mpg2=mpg1
.gen signdiff=sign(mpg2-mpg1)
.gen absdiff=abs(mpg2-mpg1)
.somersd signdiff absdiff if absdiff!=0, transf(z)

However, the result is the difference expressed as % - at least this is what I understood, but please correct me if I am wrong.

If I would like to obtain the median difference, the general syntax of cendif is supposed to be:

cendif [variable], tdist by([grouping variable])

However this syntax would presume a different organisation of the database (e.g. all results in the same column, and not mpg1 and mpg2). Am I correct?

I tried something like the t-test, I tried cendif mpg2==mpg1 or
cendif mpg2=mpg1
, but obviously it does not work.

Thanks in advance

Nicoletta