HI,
I currently have a code, where I am regressing a group of search terms on the variable 'rmrf', where I am doing a 6 month rolling regression window.
I want to regress the words and highlight those that have a negative coefficient. Then I want to use the original observations of these words and average their observations on day t. Currently, my code averages the values of the negative coefficients rather than the original observations. I am unsure on how to average the original observations using only the ones that have a negative coefficient.
Here is a sample of the dataset that I have:
I want my index to be formed by averaging those ldiffvar observations only in they have a negative coefficient when regressed with 'rmrf' in a 6 month window. Then this takes a value in the index in the following 6 months to get rid of the look ahead bias for the search terms, but at the moment the index is formed by taking the average of the negative coefficients rather than the original observations, which I am struggling to implement.
I currently have a code, where I am regressing a group of search terms on the variable 'rmrf', where I am doing a 6 month rolling regression window.
Code:
foreach v of var ldiffcost_w_res-ldiffexpense_w_res { 2. rangestat (reg) `v' rmrf, interval(ddate -183 0) 3. rename reg_nobs nobs_`v'_1 4. rename b_rmrf coef_`v'_1 5. drop reg_* b_* se_* 6. } . foreach v of varlist ldiffcost_w_res-ldiffexpense_w_res { 2. generate n_cf_`v'_1 = coef_`v'_1 if coef_`v'_1 < 0 3. } egen UKIS = rowmean(n_cf_*_1) (19 missing values generated) . replace UKIS = . if date < td(1jul2004) (181 real changes made, 181 to missing)
Here is a sample of the dataset that I have:
Code:
input int date float(ldiffcost_w_res ldiffrate_w_res ldiffexpense_w_res) double rmrf float(n_cf_ldiffcost_w_res_1 n_cf_ldiffexpense_w_res_1 UKIS) 16437 -.05834968 -.2081246 .2320308 . . . . 16438 .21403165 -.38767675 -.04747018 . -2.86213 . -10.175105 16439 -.29560152 -.12090172 -.2394834 . . . -10.388507 16440 -.0045288913 .3767251 -.03955405 .00650545 . . -4.554414 16441 .3070476 -.09433474 -.017652145 -.00828937 . . -4.424999 16442 -.27640402 .08121838 1.4430603 .00312299 . . -4.7002945 16443 -.09845573 -.12236673 -1.4207736 .00592295 . . -5.100893 16444 -.2283036 -.2081246 .2320308 . . . -4.990869 16445 .21403165 .2511179 -.04747018 . . . -4.784919 16446 .162349 -.03150256 -.2394834 -.00252512 . . -5.314806 16447 -.25534093 -.026588017 -.03955405 -.00400511 . . -4.375304 16448 .13548072 .08722775 -.017652145 -.00566278 . . -4.430126 16449 .23331444 -.005464857 -.00057517155 .00366635 . . -4.926298 16450 -.2316892 -.14046246 1.4664973 .00400246 . . -3.795078 16451 .05862203 .07656781 -1.2116047 . . . -2.679231 16452 .1452026 .18817613 -.04747018 . . . -2.693627 16453 -.14245136 -.07169075 1.204152 .00490704 . . -2.6149395 16454 -.1221075 -.3129295 -1.4831895 -.00432636 . . -2.3353891 16455 .06276067 .1920067 -.017652145 -.00006776 . . -2.457366 16456 -.27640402 -.20512307 1.4430603 -.0030091 . . -2.438887 16457 .05523642 .1639747 -1.4207736 .00027096 . . -2.171133 16458 .05862203 .19353953 .2320308 . . . -1.6369637 16459 -.0907687 -.38767675 1.3961653 . -.018644754 . -1.8115312 16460 -.08846305 .1957282 -1.6831188 .00099638 -.06898821 . -1.1924068 16461 -.0045288913 -.026588017 1.4040815 .00564778 -.13491403 . -1.1016238 16462 .0022472555 -.007651503 -1.4612876 .0009166 -.024055757 . -.9663974 16463 .010521606 -.005464857 -.00057517155 .00091163 . . -.8804716 16464 .05523642 -.035683494 .022861846 -.00358844 . . -.8549157 16465 .05862203 .28841877 1.6756662 . . . -.7230792 16466 -.0907687 -.23323277 .6433755 . . . -.6504785 16467 -.08846305 .033088222 -1.6831188 .00441636 -.016384184 . -.6539179 16468 .00642463 -.19763285 -1.4693347 .0103065 -.1269489 . -.6771828 16469 .013200777 .0977454 -.0037974084 .0024127 -.033351608 . -.8179197 16470 .021475127 -.08982645 .013279564 -.00123166 . . -.8755412 16471 .066189945 -.15203726 .03671658 .00608358 . . -1.0695547 16472 .06957555 .3210289 1.689521 . . . -.884703 16473 -.07981519 .08172207 -1.477251 . . . -1.0992079 16474 -.07750952 -.2427356 1.2180067 .00685682 -.12091915 . -.8878829 16475 .00642463 -.12084933 -1.4693347 .0032801 -.0854643 . -.9456161 16476 .013200777 .10764512 -.0037974084 .00001601 -.07801989 . -1.0210369 16477 .021475127 .005052797 .013279564 .00137872 -.10539275 . -1.1067222 16478 .066189945 .069713406 .03671658 .00766162 -.10617046 . -1.0183533 16479 .06957555 .09927821 .2458855 . . . -.9794009 16480 -.07981519 -.0230569 -.033615448 . . . -.999283 16481 -.07750952 .04360588 -.22562867 -.00053982 . . -.9853353 16482 .00642463 -.1027536 -.025699316 .00245113 . . -.9136671 16483 .013200777 -.19679207 -.0037974084 -.00114167 . . -.8710204 16484 .021475127 .204711 1.456915 .00052017 . . -.98585 16485 .066189945 -.1299448 -1.406919 -.00031131 . . -1.1184077 16486 .06957555 .2040572 1.689521 . . . -1.1990377 16487 -.07981519 .08172207 -1.477251 . . . -.9554671 16488 -.07750952 -.2427356 -.22562867 -.00076999 . . -1.1287442 16489 .00642463 .1654921 1.4179362 -.00564337 . . -.8751735 16490 .013200777 -.17869633 -1.447433 -.00701145 . . -1.0334953 16491 .021475127 -.09972617 .013279564 -.00262292 . . -.9550318 16492 .066189945 .069713406 .03671658 .00685458 . . -.7823295 16493 .06957555 .6440908 1.689521 . . . -.7421312 16494 -.07981519 -.424721 -1.477251 . . . -.7110152 16495 -.07750952 -.04307737 -.22562867 -.00625874 . . -.8545512 16496 .0019901923 .07031601 -.017967774 .0056641 . -.04460417 -.8621873 16497 .008766339 -.1789932 .0039341333 -.00099812 . . -.686049 16498 .017040689 .004755928 .021011105 .00366911 . . -.7258016 16499 .0617555 .250979 .04444812 .00430134 . . -.8277358 16500 .06514111 -.08258115 .25361705 . . . -.7602806 16501 -.08424962 -.272677 1.4177516 . . . -.726023 16502 -.08194396 .22100148 -1.6615326 -.00188178 . . -.7033923 16503 .0019901923 -.016367232 1.4256676 -.0034319 . . -.6617253 16504 .008766339 -.1789932 -1.4397013 -.00116718 . . -.6632981 16505 .017040689 .1863184 .021011105 -.00627028 . . -.6266504 16506 .0617555 -.3322476 .04444812 .00383085 . . -.5587101 16507 .06514111 .425511 .25361705 . . . -.447248 16508 -.08424962 -.377456 -.02588391 . . . -.50149727