Dear all, I am working with a panel dataset for regions, and I want to predict the effect of x1 over y1 for different regions (id) and study how this is changing over time (the plan is to use this in a second model). For that I use a multilevel model with a random coefficient for x1 at the regional level (see below), in which x1 is demeaned to study within variation. After that, I use the fixed and the predicted random effect for x1 to come with the desired measure. However, that gives a time invariant prediction (fixed for each region), since none of the fixed x1 coefficient or random x1 coefficient vary with time.
So, I am asking advice on how to let this effect to change with time. These are my current ideas:
If not, is there any other way (not necessarily within the multilevel framework) I could obtain this effect differently for regions in each year? Below there is a small data example.
Thanks in advance.
So, I am asking advice on how to let this effect to change with time. These are my current ideas:
- I could go for a multilevel model with random coefficient for x1, and repeat that model for each year. However, that would be a between regions analysis in each year (instead of a within one, right?).
- I could use a random coefficient for x1, not only for regional level, but also for time level. Even though my years are from 2006-2022, in fact it would less since I use 5 years lagged indep. variables, and I am not sure if with these number of years (11), a random coefficient for time lelvel would remain its properties.
- I could interact in the fixed part of the model x1*i.years and put each interaction as random coefficients for the regional level (but would be an endless estimation since I am talking about 11 coefficients in the random part). I tried this for more than a week and nothing came out.
If not, is there any other way (not necessarily within the multilevel framework) I could obtain this effect differently for regions in each year? Below there is a small data example.
Thanks in advance.
Code:
Iteration 122: log pseudolikelihood = -10258.05 Iteration 123: log pseudolikelihood = -10258.05 Mixed-effects nbinomial regression Number of obs = 3,006 Overdispersion: mean Group variable: id Number of groups = 254 Obs per group: min = 4 avg = 11.8 max = 12 Integration method: mvaghermite Integration pts. = 15 Wald chi2(17) = 67.13 Log pseudolikelihood = -10258.05 Prob > chi2 = 0.0000 (Std. Err. adjusted for 254 clusters in id) ---------------------------------------------------------------------------------- | Robust y1 | exp(b) Std. Err. z P>|z| [95% Conf. Interval] -----------------+---------------------------------------------------------------- x1 | L5. | 1.044958 .0216087 2.13 0.033 1.003453 1.08818 | x2 | L5. | 1.000673 .0130966 0.05 0.959 .975331 1.026674 | x3 | L5. | .9796073 .0149627 -1.35 0.177 .9507155 1.009377 | x4 | L5. | .9918395 .0124067 -0.66 0.512 .9678185 1.016457 | x5 | L5. | 1.003104 .0163533 0.19 0.849 .9715582 1.035673 | x6 | L5. | 1.016806 .0103273 1.64 0.101 .9967654 1.03725 | year | 2006 | 1 (empty) 2007 | 1 (empty) 2008 | 1 (empty) 2009 | 1 (empty) 2010 | 1 (empty) 2011 | .8308796 .0507725 -3.03 0.002 .7370956 .9365962 2012 | .9199021 .0503215 -1.53 0.127 .826377 1.024012 2013 | .9671356 .0469571 -0.69 0.491 .8793447 1.063691 2014 | .9498539 .0480901 -1.02 0.310 .8601246 1.048944 2015 | .9521785 .0425776 -1.10 0.273 .8722802 1.039395 2016 | .945086 .0369091 -1.45 0.148 .8754448 1.020267 2017 | .9209528 .0349554 -2.17 0.030 .8549278 .9920769 2018 | .9709001 .0346993 -0.83 0.409 .9052181 1.041348 2019 | .9962854 .0321001 -0.12 0.908 .9353156 1.061229 2020 | 1.015637 .0270911 0.58 0.561 .9639033 1.070147 2021 | 1.015463 .0202364 0.77 0.441 .9765646 1.05591 2022 | 1 (omitted) | _cons | 17.93158 1.77702 29.13 0.000 14.76606 21.77573 -----------------+---------------------------------------------------------------- /lnalpha | -3.738889 .1233591 -3.980668 -3.497109 -----------------+---------------------------------------------------------------- id | var(L5.x1)| .0274824 .0060578 .0178414 .0423332 var(_cons)| 2.360432 .2013258 1.997059 2.789923 -----------------+---------------------------------------------------------------- id | cov(L5.x1,_cons)| -.0466977 .0299401 -1.56 0.119 -.1053793 .0119839 ---------------------------------------------------------------------------------- Note: Estimates are transformed only in the first equation.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year float(id y1 x1 x2 x3 x4 x5 x6) 2006 1 5 -1.7775646 2.723891 -1.2291875 -1.7063985 -1.5368623 2.4518554 2007 1 5 -1.2202544 1.45774 . -1.0336447 -1.3795106 .8769412 2008 1 8 -.7455087 .3915077 -1.3092277 -.9709182 -1.1481309 -.8411472 2009 1 9 -.8487142 -1.074562 . -1.4221123 -.9250329 -2.1297135 2010 1 9 -.807432 -1.2744807 -1.2291875 -1.0288475 -.7678502 -.9843215 2011 1 7 -.0849928 -.6080854 -.50882643 -.4270809 -.5917379 .017897163 2012 1 9 .1420595 -.07496897 -.26870614 -.09886736 -.41342854 .59059274 2013 1 11 -.642303 .12494913 -.028585836 .1738537 -.27517536 -.12527741 2014 1 12 -.1881984 -.2748877 -.1886661 .2016169 -.134725 -.6979733 2015 1 7 -.06435169 .05830998 -.10862587 .29352987 .16916154 -.2684513 2016 1 8 .05949503 .4581468 -.1886661 .5043921 .472203 .017897163 2017 1 4 .03885391 -.6080854 -.3487464 1.2704383 .6129914 -.12527741 2018 1 9 .7819343 .3915077 1.0119358 1.4209753 .7389066 .4474188 2019 1 10 .4103941 -.07496897 1.0919758 1.55902 .8878076 .8769412 2020 1 13 1.6695024 -.8746439 1.4921764 -.11110864 1.1054972 -.2684513 2021 1 9 1.6695024 -.7413643 1.812337 .25691786 1.3715247 .16107106 2022 1 6 1.607579 . . 1.118244 1.8143405 . 2006 2 20 -1.9668324 2.536081 -1.357809 -2.0436459 -1.413372 2.6546836 2007 2 29 -.6613229 2.216574 -1.228494 -.9597974 -1.22389 1.2620628 2008 2 36 -.5426402 .21966097 -1.1638364 -.1650967 -1.0422335 -1.000947 2009 2 35 .849184 -.8187343 -1.0345212 -.9916811 -.9110399 -1.349102 2010 2 41 -.2297495 -.6589814 -.9698637 -.9121222 -.8287947 -.8268695 2011 2 52 -.05712012 -.6589814 -.3879454 -.28500873 -.7207753 -.8268695 2012 2 39 .09393056 -.09984569 -.12931518 -.3549016 -.6056876 .565752 2013 2 58 -.58579755 -.25959864 -.12931518 -.3371715 -.4664412 .39167455 2014 2 55 -.2297495 -.6589814 .06465752 -.1212194 -.2362404 -.3046362 2015 2 57 -.5642189 -.4193516 .25863037 .016521487 .11909527 -.13055874 2016 2 56 -.1758028 -.17972177 .06465752 .0959413 .4848315 .565752 2017 2 49 -.29448548 -.8187343 .4526029 .8584786 .6991033 .04351875 2018 2 59 -.9094776 -.01996883 1.2931515 1.3341718 .8478919 .04351875 2019 2 71 .3852426 -.6589814 1.228494 1.8900775 1.0198293 -.6527912 2020 2 51 .9678667 -.17972177 1.4224665 -.17276284 1.1881568 -.8268695 2021 2 64 1.658384 .4592908 1.6164395 .6946668 1.3712775 .39167455 2022 2 57 2.2625868 . . 1.4535483 1.7182826 . 2006 3 22 -1.461945 2.505153 -1.311473 .6374172 -1.3114537 2.560008 2007 3 26 -.7937856 1.9937345 -1.2502964 1.214219 -1.2218945 2.2027972 2008 3 25 -.5662836 .20376867 -1.2502964 1.229118 -1.1317818 -.4167453 2009 3 35 -.3920703 -.17979567 -1.1891197 .6612731 -1.042213 -.4167453 2010 3 38 -.5990766 -.05194079 -1.00559 .9011381 -.9338182 -.059535 2011 3 44 -.6298202 .0119865 -.3326478 1.2566856 -.8045746 .1786053 2012 3 50 -.4720034 -.627287 -.21029447 .8686113 -.62142 -.2976753 2013 3 63 -.6195723 -.9469237 .27911794 .26373556 -.3844877 -.4167453 2014 3 54 -.6072749 -1.1387058 -.08794144 -.37933505 -.1168786 -.7739556 2015 3 59 -.6031758 -1.010851 .0955884 -.8147325 .23368683 -.4167453 2016 3 56 -.1502212 -.3076502 .5238243 -.5586359 .5688137 -.6548856 2017 3 56 .11417311 -.3076502 .4626478 -.8629529 .8004407 -.4167453 2018 3 54 .6593583 .39555085 1.3191198 -.1474514 .9431381 .2976753 2019 3 72 1.040578 .0759141 1.3191198 -.09864163 1.050073 -.4167453 2020 3 76 1.1901965 -.8190691 1.1967665 -2.2260096 1.1619887 -1.131166 2021 3 51 1.69644 .20376867 1.441473 -1.2997588 1.2593246 .1786053 2022 3 53 2.194485 . . -.6446698 1.5510553 . 2006 4 4 -1.5086967 2.365859 -.9710394 -1.5298297 -.10335572 .6588714 2007 4 10 -.6170927 1.7043376 -.9052062 -.5740887 -.026472345 .8635697 2008 4 9 -.636063 .013781142 -.9052062 -.3030676 -.014590368 -.8763636 2009 4 16 -.7878254 -.721243 -1.0368725 -1.3405232 -.314785 -1.3881086 2010 4 18 -.10489471 -1.3092618 -1.1027057 -.8916544 -.7942577 -2.1045513 2011 4 29 -.7688551 -.13322355 -.51020706 -.0769716 -1.1290499 -.6716653 2012 4 30 -.010043235 -.13322355 -.2468744 -.1996927 -1.3562053 -.3646186 2013 4 17 -.5791521 -.6477403 -.2468744 -.3235072 -1.381367 -.9787125 2014 4 20 -.4843006 -1.603272 -.11520804 -.23814304 -1.0028912 -.4669675 2015 4 11 .008927062 -.05972085 -.3127075 -.4089962 -.198761 .2494753 2016 4 16 -.3515086 -.13322355 -.04937492 -.3687186 .4016283 .6588714 2017 4 18 .2365706 -.4272329 .279791 .3547538 .474318 .6588714 2018 4 19 -.44636005 -.20672554 1.5306215 1.0469381 .4505541 .6588714 2019 4 21 .4452439 .16078654 1.2014556 1.2479932 .5190502 .5565225 2020 4 21 2.11463 .16078654 1.5964546 .016114943 .7056671 1.1706164 2021 4 21 1.678313 .9693134 1.7939543 1.1185893 1.2829914 1.3753147 2022 4 17 1.8111053 . . 2.470794 2.487614 . 2006 5 31 -1.749826 2.312512 -1.2208925 -1.4052644 -1.1497936 1.350849 2007 5 24 -1.010769 1.3875076 -1.0342592 -.4284081 -1.0751946 .7930793 2008 5 32 -.5142152 -1.0791715 -1.0342592 -.3331871 -1.0174965 -1.438001 2009 5 40 -.12159124 -1.3875076 -.909837 -1.720246 -.9836946 -1.7168866 2010 5 39 -.6527883 -.7708373 -.909837 -1.270801 -.9373319 -1.298559 2011 5 42 -.6758839 -.2569458 -.4121484 -.51357704 -.8440959 -.1830182 2012 5 66 -.21397334 .15416707 -.34993735 -.020703495 -.7328357 -.4619037 2013 5 90 -.768266 .3597245 -.1633041 -.2914089 -.5656134 -.8802309 2014 5 85 -.2255211 1.1819502 -.28772616 -.160464 -.29499415 .3747514 2015 5 50 -.23706888 .4625032 -.03888193 -.27178133 .13294171 .6536369 2016 5 58 .59437007 .15416707 .1477513 .1735733 .53458154 .3747514 2017 5 63 -.39873755 -.6680586 .1477513 .8214886 .7439796 -.6013461 2018 5 83 .05162521 -.15416707 1.7030284 1.0372539 .8908288 -.1830182 2019 5 80 .744491 .05139033 1.391973 1.5860833 1.048656 .9325224 2020 5 90 1.67986 -1.1819502 1.5786064 -.09748574 1.1513892 1.490292 2021 5 82 1.772242 -.5652799 1.391973 1.1223526 1.3180498 .7930793 2022 5 64 1.726051 . . 1.7725903 1.7806556 . 2006 6 36 -1.8859606 1.116864 -1.1116489 -1.5856335 -1.1080685 .0109135 2007 6 47 -.8505021 .6644627 -1.0483522 -.8424931 -1.0370687 -.07639617 2008 6 57 -.3454004 -1.597542 -1.1116489 -.145503 -.9727876 -1.7352732 2009 6 57 -.067594424 -2.276143 -.9850555 -1.692368 -.9274691 -1.5606548 2010 6 49 .008170831 -1.29594 -.9850555 -1.0881214 -.9066905 -1.5606548 2011 6 63 .020798374 -.6173391 -.4786815 -.295721 -.8468712 -1.2987266 2012 6 63 .1723289 -.16493784 -.4153849 -.2681947 -.7395284 -.07639617 2013 6 70 -.50955844 .4382628 .027692353 -.10241153 -.59018755 .4474602 2014 6 76 -.067594424 .4382628 -.09890115 -.020433776 -.3464224 .4474602 2015 6 86 -.3580279 .8152636 .15428586 -.064035036 .02359635 .7966972 2016 6 70 .08393609 -.4665396 -.09890115 .12803 .3840948 .09822234 2017 6 73 -.7873644 .28746194 .15428586 .6092689 .6386773 .53476906 2018 6 67 -.7242267 .5136633 1.5468142 1.1957577 .8598221 1.233244 2019 6 95 .8415887 .28746194 1.5468142 1.2844496 1.0752081 1.0586255 2020 6 92 2.73572 .7398632 1.3569238 -.2151724 1.251735 .9713157 end
Comment