Dear Statalists,

I like to run this cross-sectional regression for my panel data and obtain only the coefficient of gamma as a variable.

retex(i, d+1, t) = alpha + beta* ret(i, d, t) + gamma * sign(retex(i, d, t))*vol(i, d, t)

where
retex(id, d+1, t): excess return for stock i on day d+1 in month t

ret(i, d, t): return for stock i on day d in month t

sign(retex(i, d, t)): the sign(positive or negative sign) for excess return of stock i on day d in month t

vol(i, d, t): trading volume for stock i on day d in month t

And in a given month, the number of days is not below 15 days.

Code:
gen month=month(date)
egen group=group(cusip year)

gen sign_positive=1 if retex>0
gen sign_negative=1 if retex<0


sort id date
bys id: gen retex_lead = retex[_n+1]

capture program drop one_regression
program define one_regression
        regress retex_lead ret  vol*sign_positive  vol*sign_negative
        if e(N) > 15 {
            gen nobs = e(N)
            forvalues i = 1/3 {
                gen b_x`i' = _b[x`i']
                gen se_x`i' = _se[x`i']
            }
        }
        exit
end

runby one_regression, by(group month) status
I do not know how to switch between sign_positive and sign_negative, instead of putting them in the same equation. Moreover, running by group month leads to errors. Can anyone help me with this please?

I really appreciate your help.

Kind regards,
Ken