Greeting,

I am trying to convert the following formula to STATA code, but I could not.
Array
The FFC is based on the mean of the cubed absolute difference between the oopctp a given household and the oopctp norm. oopctp is Out-of-pocket health payments share of household capacity to pay (oopctp)

My code is:

Code:
gen oopctp = OOP/ctp
bysort year city state: egen oopctpW = mean(oopctp)
label variable oopctp "OOP share of household capacity to pay"
Code:
gen aux = weight*(abs(oopctp - oopctpW)^3)
Code:
gen aux1 = (aux/weight)^(1/3)
Code:
gen FFC = 1 - aux1
I would greatly appreciate any valuable advice in this regard.