Hello everyone,
I am trying to run a panel regression with a rolling window in order to obtain the coefficients over a regression window of 60 months each.
I already ran a similar regression with another dataset for each company ID, where I used the user-contributed command by @Attaullah Shah. This worked perfectly fine for a "static regression".
I used the following code:
For the regression with a rolling window I was trying to use the same code, but I added a rolling window. However, the output generated was not what I needed. That's the code I used.
The goal is to use the first 60 months of each company ID and obtain the coefficients and then move on to the next months 2-61, 3-62...etc. In total I would need 19 times a regression of 60 months of data for each company ID.
Can anyone help me with this issue? Is the format of the date variable the problem?
Here, is a sample of my dataset:
Thank you in advance, I really appreciate your help.
Nicole
I am trying to run a panel regression with a rolling window in order to obtain the coefficients over a regression window of 60 months each.
I already ran a similar regression with another dataset for each company ID, where I used the user-contributed command by @Attaullah Shah. This worked perfectly fine for a "static regression".
I used the following code:
Code:
bys ID: asreg ExcReturn SMB_ HML_ MOM_ MktRfECB_
Code:
bys ID: asreg ExcReturn SMB_ HML_ MOM_ MktRfECB_, window(date 60) rec
The goal is to use the first 60 months of each company ID and obtain the coefficients and then move on to the next months 2-61, 3-62...etc. In total I would need 19 times a regression of 60 months of data for each company ID.
Can anyone help me with this issue? Is the format of the date variable the problem?
Here, is a sample of my dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int ID double(Month_ SMB_ HML_ MOM_ RFECB_ MktRfECB_ MktReturn_) float(date ExcReturn) 1 -.00816331063916087 -.022000000000000002 .0031 -.0354 .00007855771554621249 .017621442284453788 .0177 19814 -.008241869 1 .11937058956974622 .0218 .0033 -.021400000000000002 -.00021591622453487336 .04811591622453487 .0479 20179 .1195865 1 .026416105733352294 -.0064 .0335 -.0391 -.0004327660911997988 .024332766091199796 .023899999999999998 20545 .02684887 1 .04648614431204509 .0191 -.013000000000000001 .0023 -.0006415446871788077 .0474415446871788 .046799999999999994 20910 .04712769 1 .0932324728445517 -.0074 .0151 .006999999999999999 -.0005511845246031211 .023951184524603125 .023400000000000004 21275 .09378365 1 .006035021334470299 .001 -.0104 -.043899999999999995 -.0004975216476115207 .039597521647611524 .0391 21640 .006532543 1 .17276286720240136 .0504 -.0381 .0102 -.0005123043778888503 .06763044313488914 .06709999999999999 22006 .17327517 1 .08400792777071235 -.0097 -.0101 .0033 -.00004614420928317209 -.00015385579071682792 -.0002 19936 .08405408 1 -.06136894637629213 .037000000000000005 -.01 .0212 -.00022122731331630785 -.05997877268668369 -.0602 20301 -.06114772 1 .15202688358818803 .0161 .019299999999999998 -.0176 -.0005377819706646747 .008537781970664675 .008 20667 .15256466 1 .010062541533153058 -.0006 -.0070999999999999995 .013300000000000001 -.0006406257274652605 .0026406257274652605 .002 21032 .010703167 1 -.13255300343537135 .0088 -.0265 .0242 -.0005609230927768882 -.02433907690722311 -.0249 21397 -.13199209 1 -.08654045633105636 -.0059 -.0196 .032799999999999996 -.0007383804296020591 -.021661619570397937 -.022399999999999996 21762 -.08580208 1 .018388373587279568 . -.0174 . -.0005220002253455425 .050180869664140725 .0496 22128 .018910374 1 .016360283105206853 .0222 -.0235 .019799999999999998 -.00007543879269333864 -.036924561207306666 -.037000000000000005 20058 .016435722 1 -.052814265545862445 .0377 -.0125 .0401 -.00033127876821847924 -.018168721231781523 -.018500000000000003 20423 -.05248298 1 .14336906537841607 -.0083 .0199 -.0196 -.0006879671832880074 .04818796718328801 .0475 20789 .14405704 1 .044260268220982765 .0155 .005 -.014199999999999999 -.0006169843835842626 .016216984383584265 .015600000000000001 21154 .04487725 1 -.008057339919867698 -.0068000000000000005 .0095 .032400000000000005 -.0006263079412752726 -.043373692058724725 -.044 21519 -.007431032 1 -.023327191657974266 .0279 .0040999999999999995 .0166 -.0005522660704037063 .042652266070403705 .0421 21884 -.022774925 1 .08361878069589906 .009899999999999999 .0196 -.0397 -.00020577021794732087 .06230577021794732 .0621 20120 .08382455 1 .007490671729157438 .014499999999999999 .0037 -.006999999999999999 -.00042645801152185747 -.01647354198847814 -.0169 20485 .007917129 1 -.003856721896140414 -.0004 -.026000000000000002 -.016 -.0007371765285624221 .007937176528562424 .007200000000000001 20851 -.003119545 1 -.07312743854956623 .012199999999999999 -.0075 .0062 -.0005693344001306277 -.05183066559986937 -.052399999999999995 21216 -.072558105 1 -.010465532039661263 -.0147 -.0123 -.0115 -.0004739644158900935 .031573964415890096 .031100000000000003 21581 -.009991568 1 -.1420618825082541 .0029 -.0073 .0077 -.000615196470831636 -.08796507329364876 -.0886 21946 -.14144668 1 .15588779665087954 -.015600000000000001 -.0352 .0351 -.00015317648082147084 -.002946823519178529 -.0031 20089 .15604097 1 -.030783650296596226 -.0076 -.0149 .0115 -.0003764425891231715 -.06382355741087682 -.0642 20454 -.030407207 1 .03019588837589893 .0203 .004699999999999999 .028300000000000002 -.0005873520266435062 .029387352026643505 .0288 20820 .03078324 1 -.032184649785555026 .008 .011000000000000001 .0296 -.0005344406522276302 .056834440652227626 .056299999999999996 21185 -.031650208 1 -.1981769285837487 .0059 -.0095 -.0223 -.0005030402745956897 .06450304027459569 .064 21550 -.1976739 1 -.030170877633363354 .0036 -.0288 .0355 -.0005461374810858954 -.023653862518914104 -.0242 21915 -.02962474 1 -.09339286142578701 -.0043 .004 -.0058 -.000014963731461481444 -.04098503626853851 -.040999999999999995 19905 -.0933779 1 .06288908854893364 -.008100000000000001 -.0265 .0353 -.0002425140438256923 .024142514043825693 .0239 20270 .0631316 1 .030580837179675368 .0154 .0021 -.001 -.000533995543566923 .045133995543566924 .0446 20636 .031114833 1 .0856965565583179 .008 .0259 .0196 -.0005935362407027966 .036193536240702796 .0356 21001 .0862901 1 .028620105510629996 -.0191 .004 -.005600000000000001 -.0005458893280377852 .029045889328037786 .0285 21366 .029165994 1 -.07071849745442123 -.0128 .0009 .0139 -.000621993411462296 -.023078006588537706 -.023700000000000002 21731 -.07009651 1 -.004736284418952219 .0269 -.0475 .06709999999999999 -.0005421838800333534 .04061519647083164 .04 22097 -.0041941004 1 .08171416718983518 .0011 -.0176 .0033 -7.576149014587585e-06 -.0011924238509854123 -.0012 19875 .08172175 1 -.0535599932604153 .0203 .0016 .0091 -.00021596383750988046 -.028184036162490118 -.028399999999999998 20240 -.05334403 1 -.05728560793831404 -.0239 -.016399999999999998 .071 -.0005425108252492539 -.049357489174750746 -.0499 20606 -.0567431 1 -.0597302473716993 .0155 .0203 .0159 -.0005454885958302569 -.005554511404169744 -.006100000000000001 20971 -.05918476 1 -.22023596878813692 -.0085 -.015600000000000001 -.0066 -.0005918813161841507 -.00720811868381585 -.0078000000000000005 21336 -.2196441 1 .09696672352935749 -.0269 -.013999999999999999 -.0039000000000000003 -.0005774026413249977 .061477402641324994 .060899999999999996 21701 .09754413 1 .01123121956950048 -.012 .0174 .0075 -.0005323911586925245 .0410461374810859 .0405 22067 .01176361 1 -.02341964372585837 -.0051 -.0034999999999999996 .015700000000000002 -.0002075225303665995 -.022592477469633398 -.022799999999999997 20148 -.02321212 1 -.0733227345790196 .0171 .011899999999999999 -.0149 -.0004056161622540966 .06760561616225409 .0672 20514 -.07291712 1 .09531017980432474 -.013000000000000001 .005 .0002 -.0006217391777666448 .04362173917776664 .043 20879 .09593192 1 -.12355023937854125 -.005600000000000001 -.009399999999999999 -.0043 -.000583153409159487 -.005316846590840513 -.0059 21244 -.12296709 1 -.08912777989600727 -.0176 -.0233 .0452 -.0005100090045742078 .008210009004574208 .0077 21609 -.08861777 1 -.07490707719864281 -.042199999999999994 -.113 .0755 -.0005808696641407263 -.15382553759897422 -.15439999999999998 21975 -.07432621 1 .01074681456735932 -.006999999999999999 -.0034000000000000002 -.0023 .000025779677764292686 .0076742203222357076 .0077 19844 .010721035 1 .005784542521529858 .0166 -.024700000000000003 .0356 -.00020487904055832562 -.0012951209594416744 -.0015 20209 .005989422 1 .015250840252466894 .015300000000000001 -.0287 .0381 -.0004500314028320629 -.0032499685971679373 -.0037 20575 .015700871 1 .12721129003781229 .0002 -.0079 -.0043 -.0006191280794665133 .051519128079466514 .0509 20940 .12783042 1 0 .0123 -.0499 .02 -.0006015000952903637 -.025298499904709636 -.0259 21305 .0006015001 1 -.23342486353013098 .0132 -.0154 .085 -.0005363292448664625 -.050763670755133536 -.0513 21670 -.23288853 1 .08047720691999859 .0121 -.0414 .028999999999999998 -.0004993432769760942 .05495226607040371 .054400000000000004 22036 .08097655 1 .03639309950313204 -.013500000000000002 -.0182 -.0062 -.00005277948517878883 .02125277948517879 .0212 20028 .03644588 1 -.1455164305948154 .0033 -.027999999999999997 .026099999999999998 -.0003366492978409408 -.01456335070215906 -.0149 20393 -.14517978 1 -.1513916193328682 .0089 .0192 -.020499999999999997 -.0006653913750100937 -.02423460862498991 -.024900000000000002 20759 -.15072623 1 .0720891014517267 -.0038 .0129 .003 -.0006395834118079202 .0013395834118079203 .0007000000000000001 21124 .072728686 1 .08268402912507528 -.0118 -.005699999999999999 -.0209 -.0005811061712430732 -.010718893828756928 -.011300000000000001 21489 .08326513 1 -.011884689971514095 .0207 -.022400000000000003 .006999999999999999 -.000530443134889147 .019430443134889147 .0189 21854 -.011354247 1 .03850820866998566 -.0123 -.030899999999999997 .0108 -.00006792286859436114 -.026932077131405642 -.027000000000000003 19997 .03857613 1 .024530032709535948 -.0297 -.0077 -.015600000000000001 -.0002752571670172621 .062175257167017266 .061900000000000004 20362 .02480529 1 -.03030534949532915 -.0077 .0636 -.0083 -.0006195845128315058 -.029980415487168496 -.030600000000000002 20728 -.029685766 1 .033187050937816424 -.0096 -.0013 .012199999999999999 -.0006588161449018193 .007458816144901819 .0068 21093 .033845868 1 -.01680711831638129 -.017 .0147 -.0147 -.0006111643575186232 -.08288883564248137 -.08349999999999999 21458 -.016195955 1 -.17738675650810648 .009300000000000001 -.005 -.011899999999999999 -.000574462401025766 .03477446240102577 .0342 21823 -.1768123 1 -.07713249420127181 -.022799999999999997 -.0044 .024900000000000002 -.00007915361669907917 -.037820846383300924 -.0379 19967 -.07705334 1 .1633666713289294 .0111 -.0363 .042800000000000005 -.0002257016327344985 -.042474298367265496 -.042699999999999995 20332 .16359237 1 .029947631730827647 .0092 -.0015 .031400000000000004 -.0006034823597192984 .010303482359719299 .0097 20698 .030551113 1 .02286789069121414 -.0012 .004699999999999999 .0063 -.0006278602823639456 .028727860282363946 .0281 21063 .02349575 1 -.0341713565449153 -.0146 .023399999999999997 .0159 -.0005266067230381699 .00322660672303817 .0027 21428 -.03364475 1 .1328249284481955 -.0089 .0308 -.022799999999999997 -.0006349267063512354 .023934926706351237 .0233 21793 .13345985 1 -.21997062427363212 .0291 -.0374 .0004 -.0005383058965158227 -.02908769562211115 -.0296 22159 -.21943232 2 .03049697112210658 -.022000000000000002 .0031 -.0354 .00007855771554621249 .017621442284453788 .0177 19814 .03041841 2 .011204599012863062 .0218 .0033 -.021400000000000002 -.00021591622453487336 .04811591622453487 .0479 20179 .011420515 2 .04345136577836155 -.0064 .0335 -.0391 -.0004327660911997988 .024332766091199796 .023899999999999998 20545 .04388413 2 .014706147389695487 .0191 -.013000000000000001 .0023 -.0006415446871788077 .0474415446871788 .046799999999999994 20910 .015347692 2 .10249928337679416 -.0074 .0151 .006999999999999999 -.0005511845246031211 .023951184524603125 .023400000000000004 21275 .10305047 2 .03089048701933851 .001 -.0104 -.043899999999999995 -.0004975216476115207 .039597521647611524 .0391 21640 .031388007 2 .022353245780747908 .0504 -.0381 .0102 -.0005123043778888503 .06763044313488914 .06709999999999999 22006 .02286555 2 .067565319495766 -.0097 -.0101 .0033 -.00004614420928317209 -.00015385579071682792 -.0002 19936 .06761146 2 -.17273092629225284 .037000000000000005 -.01 .0212 -.00022122731331630785 -.05997877268668369 -.0602 20301 -.1725097 2 .07796154146971192 .0161 .019299999999999998 -.0176 -.0005377819706646747 .008537781970664675 .008 20667 .07849932 2 .18481345940413357 -.0006 -.0070999999999999995 .013300000000000001 -.0006406257274652605 .0026406257274652605 .002 21032 .1854541 2 .04573600932268429 .0088 -.0265 .0242 -.0005609230927768882 -.02433907690722311 -.0249 21397 .04629693 2 .010582109330537008 -.0059 -.0196 .032799999999999996 -.0007383804296020591 -.021661619570397937 -.022399999999999996 21762 .01132049 2 -.11672427430814143 . -.0174 . -.0005220002253455425 .050180869664140725 .0496 22128 -.11620227 2 -.029980832211935784 .0222 -.0235 .019799999999999998 -.00007543879269333864 -.036924561207306666 -.037000000000000005 20058 -.029905394 2 .00473560474583425 .0377 -.0125 .0401 -.00033127876821847924 -.018168721231781523 -.018500000000000003 20423 .005066883 2 .07302513501488982 -.0083 .0199 -.0196 -.0006879671832880074 .04818796718328801 .0475 20789 .0737131 2 .02504793886917213 .0155 .005 -.014199999999999999 -.0006169843835842626 .016216984383584265 .015600000000000001 21154 .025664924 2 -.1004705303636345 -.0068000000000000005 .0095 .032400000000000005 -.0006263079412752726 -.043373692058724725 -.044 21519 -.09984422 2 .11240956759524014 .0279 .0040999999999999995 .0166 -.0005522660704037063 .042652266070403705 .0421 21884 .11296184 2 .06326544649077304 .009899999999999999 .0196 -.0397 -.00020577021794732087 .06230577021794732 .0621 20120 .06347122 2 -.00340136382349029 .014499999999999999 .0037 -.006999999999999999 -.00042645801152185747 -.01647354198847814 -.0169 20485 -.002974906 end format %td date
Thank you in advance, I really appreciate your help.
Nicole
Comment