Hello,

I am working on a project where I need to runby the corr program and return the correlation in the generated variables.
Code:
program my_corr
    pwcorr resid_rm resid_x resid_r
    mat c = r(C)
    gen rm_x_corr = c[2,1]
    gen rm_r_corr = c[3,1]
    gen x_r_corr = c[3,2]
    gen rm_x_t = rm_x_corr*(count_permno-2)^0.5/ (1-rm_r_corr^2)^0.5
    gen rm_r_t = rm_r_corr*(count_permno-2)^0.5/ (1-rm_r_corr^2)^0.5
    gen x_r_t = x_r_corr*(count_permno-2)^0.5/ (1-x_r_corr^2)^0.5
end
runby my_corr, by(id) verbose
-runby- successfully excuses when id is less than 10,000. When I try to implement -runby- with my_corr, it has the error:
Code:
 store_data():  3900  unable to allocate real <tmp>[2893885,1]
            runby_main():     -  function returned error
                 <istmt>:     -  function returned error
After googling the error message, I believe the error is raised due to memory problem. It seems that -runby- would record the results of the program in a big matrix for each by(id).
How can I solve this problem? Is it possible that I return the values in the big matrix and then clear the results in the big matrix for each by(id)?

The complete data range for 55 years, and -runby- bumps into the error when I try to apply it in a 2-year data. Therefore, I would love not split the data for each year and run 55 times.
Any comment and advice is welcome