I am trying to write the syntax to calculate the median number of visits per facility in a data set where each row/case is one visit. In Stata I would do:
bysort providercode: gen littlen=_n
bysort providercode: gen bign=_N
keep if little==big
centile little, centile (1 50 100)
However I need to write it in SPSS. I have got this far. The variable called 'count' is the equivalent of _n, which counts up by one for each record within each facility:
sort cases by providercode.
compute count = 1.
if providercode = lag(providercode) count = lag(count) + 1.
execute.
Now I need to calculate _N within providercode.
Can anyone help/advise please?
Thanks