Hi everyone.

I am trying to generate abnormal returns in STATA.
To do so, I need to calculate the expected returns (Expected return = α+β*R)
R is the average return of the market, for which I want to do a value weighted calculation (with returns and market capitalization)
I have a dataset with around 550 companies and for each company I have more than 300 daily returns and the associated market cap for the day.

I was able to calculate the average market return for one day by doing the following:

egen num=total(QJ*QK)
egen den=total(QJ)
gen wtmean=num/den


My Variables are named from QJ, QK, QL,...,ATI.
QJ is daily market cap, QK daily return
QL is daily market cap, QM daily return
and so on (every second variable is market cap)

I want to create wtmean for every day and then calculate the mean, so that I have the average return for the market for the time period I am looking at.

Can anyone help me on how to create the average return for the market? I already tried foreach but I didn't find the right code, as I don't know how to address only every second variable.