Dear Stata users,
I am currently trying to replicate a paper, where Vector Autoregression is applied per stock in the whole US market and per year from 1960 to 2015. To get the average across stocks and years, I have to save the results from the VAR such as coefficient and significance level.
However, I have the issue with computation capacity in my computer. For example, I have tried running the syntax for the whole day, and only around 1% is computed. If I keep on the same method, then it takes months to accomplish the computation.
Therefore, I would love have suggestion from your side, to see how I can amend this situation from the syntax side, or from any other sides.
Below is my syntax for VAR loop, where id is the group index of stock and year. For example, Stock 1 in year 1 is 1, and stock 1 in year 2 is 2. Id has around 160,000. The syntax aims to generate the variables regarding to the VAR variables and the legs. The local count function is to avoid record the constant values, which are not required in my project.
Code:
I am currently trying to replicate a paper, where Vector Autoregression is applied per stock in the whole US market and per year from 1960 to 2015. To get the average across stocks and years, I have to save the results from the VAR such as coefficient and significance level.
However, I have the issue with computation capacity in my computer. For example, I have tried running the syntax for the whole day, and only around 1% is computed. If I keep on the same method, then it takes months to accomplish the computation.
Therefore, I would love have suggestion from your side, to see how I can amend this situation from the syntax side, or from any other sides.
Below is my syntax for VAR loop, where id is the group index of stock and year. For example, Stock 1 in year 1 is 1, and stock 1 in year 2 is 2. Id has around 160,000. The syntax aims to generate the variables regarding to the VAR variables and the legs. The local count function is to avoid record the constant values, which are not required in my project.
Code:
Code:
su id, meanonly set trace on forvalue i = 1/`r(max)'{ display `i' var sprtrn sign_trading ret if id == `i', lags(1/5) mat t = r(table) predict rid_rm if id == `i', residuals equation (sprtrn) predict rid_x if id == `i', residuals equation (sign_trading) predict rid_r if id == `i', residuals equation (ret) replace resid_rm = rid_rm if !missing(rid_rm) replace resid_x = rid_x if !missing(rid_x) replace resid_r = rid_r if !missing(rid_r) drop rid_rm rid_x rid_r local count = 0 foreach k in rm x r{ forvalues m = 1/5{ replace rm_`k'_l`m'_coef = t[1,`= `m' + `count''] if id == `i' replace rm_`k'_l`m'_t = t[3,`= `m' + `count''] if id == `i' } local count = `count' +5 } local count = `count'+1 foreach k in rm x r{ forvalues m = 1/5{ replace x_`k'_l`m'_coef = t[1,`= `m' + `count''] if id == `i' replace x_`k'_l`m'_t = t[3,`= `m' + `count''] if id == `i' } local count = `count' +5 } local count = `count'+1 foreach k in rm x r{ forvalues m = 1/5{ replace r_`k'_l`m'_coef = t[1,`= `m' + `count''] if id == `i' replace r_`k'_l`m'_t = t[3,`= `m' + `count''] if id == `i' } local count = `count' +5 } } set trace off
Comment