Dear stata users,


I am now regress anomalies of the long-short strategy during different investor sentiment period. I've sort the sentiment period into high sentiment and low sentiment period. I can regress the anomalies during high sentiment and low sentiment separately. Now i have to regress the difference between high and low sentiment period, and this is where my problem is.

Can anyone tell me how to use the returns during high sentiment to minus the ones during low sentiment and run the regression?

Thank you in advance!

here's part of my code :

Code:
/
//for the long leg
*during period of high sentiment
gen long_high = .
replace long_high = long_excess if High == 1
reg long_high, robust

*during period of low sentiment
gen long_low = .
replace long_low = long_excess if Low == 1
reg long_low, robust

// I also tried this to compare the return difference during these two periods, but i thought this is not quite convenient and might be wrong
// firstly i save the data as in the profile and then do the following:
use "2_data_output/9_T2_H&L", clear
keep  long_high
drop if long_high == .
gen t = [_n]
save "2_data_output/9_t2_long_high", replace

use "2_data_output/9_T2_H&L", clear
keep  long_low
drop if long_low == .
gen t = [_n]

merge 1:1 t using  "2_data_output/9_t2_long_high"
drop if _merge != 3
drop _merge

gen long_high_low = long_high - long_low
reg long_high_low, robust
Here's my data
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(year month long_excess short_excess spread_excess High Low long_high long_low short_high short_low spread_high spread_low)
1965  8    2.113655  4.5946918  -2.481037 . 1          .    2.113655          .  4.5946918          .  -2.481037
1965  9    2.712177  1.7329366   .9792402 . 1          .    2.712177          .  1.7329366          .   .9792402
1965 10    2.608835   3.831703 -1.2228682 . 1          .    2.608835          .   3.831703          . -1.2228682
1965 11   -.4219974  1.0842466  -1.506244 . 1          .   -.4219974          .  1.0842466          .  -1.506244
1965 12    .5496983  -1.903147   2.452845 . 1          .    .5496983          .  -1.903147          .   2.452845
1966  1    .2819972   .9168789  -.6348817 . 1          .    .2819972          .   .9168789          .  -.6348817
1966  2   -3.916921   2.945797  -6.862718 . 1          .   -3.916921          .   2.945797          .  -6.862718
1966  3  -4.2584186 -.26062697 -3.9977915 . 1          .  -4.2584186          . -.26062697          . -3.9977915
1966  4   -.3266898   5.688498  -6.015188 . 1          .   -.3266898          .   5.688498          .  -6.015188
1966  5  -4.0639577  -3.930259  -.1336987 . 1          .  -4.0639577          .  -3.930259          .  -.1336987
1966  6  -3.0536065 -2.2476447  -.8059618 . 1          .  -3.0536065          . -2.2476447          .  -.8059618
1966  7  -3.1833386 -4.3205814  1.1372428 . 1          .  -3.1833386          . -4.3205814          .  1.1372428
1966  8   -8.476387 -11.618307    3.14192 . 1          .   -8.476387          . -11.618307          .    3.14192
1966  9  -1.1963408 -2.1784227   .9820819 . 1          .  -1.1963408          . -2.1784227          .   .9820819
1966 10   -.7408968   2.609444 -3.3503404 . 1          .   -.7408968          .   2.609444          . -3.3503404
1966 11   1.6910785  11.858765 -10.167686 . 1          .   1.6910785          .  11.858765          . -10.167686
1966 12    5.621592  -4.263537   9.885129 . 1          .    5.621592          .  -4.263537          .   9.885129
1967  1   10.973114   8.700139   2.272975 . 1          .   10.973114          .   8.700139          .   2.272975
1967  2     3.50877  2.3290498  1.1797202 . 1          .     3.50877          .  2.3290498          .  1.1797202
1967  3    4.652876   4.805441  -.1525655 . 1          .    4.652876          .   4.805441          .  -.1525655
1967  4   -.5550592    7.44843  -8.003489 . 1          .   -.5550592          .    7.44843          .  -8.003489
1967  5   1.1850634  -5.857903   7.042966 . 1          .   1.1850634          .  -5.857903          .   7.042966
1967  6    3.244605   2.788834  .45577145 . 1          .    3.244605          .   2.788834          .  .45577145
1967  7    7.115045   3.874219   3.240826 . 1          .    7.115045          .   3.874219          .   3.240826
1967  8  -.10974194 -1.5687592  1.4590173 . 1          .  -.10974194          . -1.5687592          .  1.4590173
1967  9   1.1386691   2.288789 -1.1501199 . 1          .   1.1386691          .   2.288789          . -1.1501199
1967 10   -4.921431  1.4329666  -6.354398 . 1          .   -4.921431          .  1.4329666          .  -6.354398
1967 11 -.008102045  1.7566234 -1.7647254 . 1          . -.008102045          .  1.7566234          . -1.7647254
1967 12    2.704828  2.1337602   .5710678 . 1          .    2.704828          .  2.1337602          .   .5710678
1968  1   1.8896433  -10.73514  12.624783 . 1          .   1.8896433          .  -10.73514          .  12.624783
1968  2  -3.1467705   -5.18183  2.0350595 . 1          .  -3.1467705          .   -5.18183          .  2.0350595
1968  3  -1.5454537  2.5023074  -4.047761 1 . -1.5454537           .  2.5023074          .  -4.047761          .
1968  4    8.421733  12.663926  -4.242193 1 .   8.421733           .  12.663926          .  -4.242193          .
1968  5   2.8999364   3.738553  -.8386168 . 1          .   2.8999364          .   3.738553          .  -.8386168
1968  6   .23074245   -2.68006  2.9108026 1 .  .23074245           .   -2.68006          .  2.9108026          .
1968  7  -2.1535227  -7.006055   4.852532 1 . -2.1535227           .  -7.006055          .   4.852532          .
1968  8   1.8048393    1.12887   .6759692 1 .  1.8048393           .    1.12887          .   .6759692          .
1968  9    6.120957  4.5526276  1.5683298 1 .   6.120957           .  4.5526276          .  1.5683298          .
1968 10    1.818216  -2.507424  4.3256397 1 .   1.818216           .  -2.507424          .  4.3256397          .
1968 11    5.498557   7.994974  -2.496417 1 .   5.498557           .   7.994974          .  -2.496417          .
1968 12    -.711086   -3.70512   2.994034 1 .   -.711086           .   -3.70512          .   2.994034          .
1969  1    .7924113  -2.956972  3.7493834 1 .   .7924113           .  -2.956972          .  3.7493834          .
1969  2   -6.762702 -8.8334465   2.070744 1 .  -6.762702           . -8.8334465          .   2.070744          .
1969  3    .1519336   .6217533  -.4698197 1 .   .1519336           .   .6217533          .  -.4698197          .
1969  4     2.56019   .6804342  1.8797557 1 .    2.56019           .   .6804342          .  1.8797557          .
1969  5  -2.1312907 -2.9841974   .8529067 1 . -2.1312907           . -2.9841974          .   .8529067          .
1969  6  -11.403998  -9.102878 -2.3011208 1 . -11.403998           .  -9.102878          . -2.3011208          .
1969  7   -6.616497  -11.12009  4.5035934 1 .  -6.616497           .  -11.12009          .  4.5035934          .
1969  8    2.021029  8.5742035  -6.553174 1 .   2.021029           .  8.5742035          .  -6.553174          .
1969  9  -1.5112845 -4.4802976   2.969013 1 . -1.5112845           . -4.4802976          .   2.969013          .
1969 10     7.77114   8.298175 -.52703524 1 .    7.77114           .   8.298175          . -.52703524          .
1969 11   -6.602033  -4.342446 -2.2595873 1 .  -6.602033           .  -4.342446          . -2.2595873          .
1969 12   -5.228517  -3.402241 -1.8262756 1 .  -5.228517           .  -3.402241          . -1.8262756          .
1970  1   -5.842575 -13.032257   7.189682 1 .  -5.842575           . -13.032257          .   7.189682          .
1970  2    5.018503   4.762554  .25594902 1 .   5.018503           .   4.762554          .  .25594902          .
1970  3    .7580438 -4.7515993   5.509643 1 .   .7580438           . -4.7515993          .   5.509643          .
1970  4  -10.637965 -19.424294   8.786328 1 . -10.637965           . -19.424294          .   8.786328          .
1970  5  -3.4445906 -10.640683   7.196093 1 . -3.4445906           . -10.640683          .   7.196093          .
1970  6   -7.292585  -9.535181  2.2425957 1 .  -7.292585           .  -9.535181          .  2.2425957          .
1970  7    6.853394   5.770004  1.0833893 1 .   6.853394           .   5.770004          .  1.0833893          .
1970  8    4.534803   7.585699  -3.050896 1 .   4.534803           .   7.585699          .  -3.050896          .
1970  9    3.846845   9.783924  -5.937079 1 .   3.846845           .   9.783924          .  -5.937079          .
1970 10   -3.250186 -3.5721774   .3219914 1 .  -3.250186           . -3.5721774          .   .3219914          .
1970 11    4.425929  3.4717596   .9541695 1 .   4.425929           .  3.4717596          .   .9541695          .
1970 12    6.508982  2.3686438   4.140338 1 .   6.508982           .  2.3686438          .   4.140338          .
1971  1    9.604625    7.97692  1.6277046 1 .   9.604625           .    7.97692          .  1.6277046          .
1971  2    .3284841 -.53091806   .8594022 1 .   .3284841           . -.53091806          .   .8594022          .
1971  3    3.756774   5.680111 -1.9233372 1 .   3.756774           .   5.680111          . -1.9233372          .
1971  4    3.434862   3.554248 -.11938667 1 .   3.434862           .   3.554248          . -.11938667          .
1971  5   -3.117192  -3.370032  .25283957 . 1          .   -3.117192          .  -3.370032          .  .25283957
1971  6  -1.7789034  1.2264736  -3.005377 . 1          .  -1.7789034          .  1.2264736          .  -3.005377
1971  7   -8.251288  -6.454547  -1.796741 . 1          .   -8.251288          .  -6.454547          .  -1.796741
1971  8    5.990544   4.298956   1.691588 . 1          .    5.990544          .   4.298956          .   1.691588
1971  9   -2.385594    -.41497  -1.970624 . 1          .   -2.385594          .    -.41497          .  -1.970624
1971 10    -7.80325  -6.237272  -1.565978 . 1          .    -7.80325          .  -6.237272          .  -1.565978
1971 11   -1.431545   .9477333 -2.3792782 . 1          .   -1.431545          .   .9477333          . -2.3792782
1971 12   12.232764  11.513345   .7194195 . 1          .   12.232764          .  11.513345          .   .7194195
1972  1   11.357686   4.134503   7.223183 . 1          .   11.357686          .   4.134503          .   7.223183
1972  2   4.6878734   4.168227  .51964617 . 1          .   4.6878734          .   4.168227          .  .51964617
1972  3   -1.923905  -.1767674 -1.7471377 . 1          .   -1.923905          .  -.1767674          . -1.7471377
1972  4    .4149056  2.1147425  -1.699837 . 1          .    .4149056          .  2.1147425          .  -1.699837
1972  5  -2.9860954  2.2239296  -5.210025 . 1          .  -2.9860954          .  2.2239296          .  -5.210025
1972  6   -3.054416  -2.936456 -.11796045 . 1          .   -3.054416          .  -2.936456          . -.11796045
1972  7   -2.748778 -2.9789865  .23020864 . 1          .   -2.748778          . -2.9789865          .  .23020864
1972  8    4.824571   1.774485   3.050086 . 1          .    4.824571          .   1.774485          .   3.050086
1972  9  -4.3545446  -2.226455 -2.1280897 . 1          .  -4.3545446          .  -2.226455          . -2.1280897
1972 10   -.8215827  -3.248502   2.426919 . 1          .   -.8215827          .  -3.248502          .   2.426919
1972 11    5.188623   7.695151 -2.5065284 . 1          .    5.188623          .   7.695151          . -2.5065284
1972 12   -3.057254    .610857  -3.668111 . 1          .   -3.057254          .    .610857          .  -3.668111
1973  1   -5.262606  -7.212911  1.9503045 . 1          .   -5.262606          .  -7.212911          .  1.9503045
1973  2    -6.05538  -8.112985  2.0576043 . 1          .    -6.05538          .  -8.112985          .  2.0576043
1973  3  -2.0585976 -3.9437394   1.885142 . 1          .  -2.0585976          . -3.9437394          .   1.885142
1973  4   -7.395673  -7.887769  .49209595 . 1          .   -7.395673          .  -7.887769          .  .49209595
1973  5   -7.236129  -7.466108   .2299795 . 1          .   -7.236129          .  -7.466108          .   .2299795
1973  6    -2.52135  -4.334335  1.8129847 . 1          .    -2.52135          .  -4.334335          .  1.8129847
1973  7     7.83624  14.489782  -6.653542 . 1          .     7.83624          .  14.489782          .  -6.653542
1973  8   -3.230599 -4.5253963  1.2947972 . 1          .   -3.230599          . -4.5253963          .  1.2947972
1973  9   11.200712  10.135047  1.0656652 . 1          .   11.200712          .  10.135047          .  1.0656652
1973 10   1.1378112  -.4050448   1.542856 . 1          .   1.1378112          .  -.4050448          .   1.542856
1973 11   -10.55416  -19.71132   9.157164 . 1          .   -10.55416          .  -19.71132          .   9.157164
end