Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Event Based Model with not estimable margin problem

    Hello All,
    I am building event based model to check the effect of Covid-19 policies in US. I built it using fixed effect regression. the model is studying the impact of mask policy in counties that applied business close or not. after building the regression i got results and coefficient as follows:

    Click image for larger version

Name:	2.jpg
Views:	1
Size:	458.7 KB
ID:	1634630





    I see the coefficient for last two days are omitted. when I tried to get margin using margin command I got (not estimable) message for all coefficients. I read a lot on your website and see one solution by using noestimcheck margin. I got results for margin after using this command. My question is if I can adopt these results of margin on my research. is it accurate results that I can use it? I appreciate your help as I need help to complete my research and submit my results after being sure about it.


    My code:
    g busniss_policy=business_delta_day


    replace busniss_policy=1 if busniss_policy>=0

    replace busniss_policy=0 if busniss_policy<0


    * to rprint coeff significant statistics->postestimator->managepst results->table by adding business_delta_day>0 means these counties applied business close policy



    reghdfe cases_normed i.shifted_ttt11#busniss_policy cases_normed_delay_14days cases_normed_delay_14days_growth residential workplaces transit_stations parks grocery_and_pharmacy retail_and_recreation grocery_and_pharmacy_sq retail_and_recreation_sq parks_sq transit_stations_sq workplaces_sq if shifted_ttt11<=368 & shifted_ttt11>=331&mask!="2077-12-31", absorb(fips time) vce(cluster fips)

    margins shifted_ttt11#busniss_policy,noestimcheck
    Last edited by amera amery; 03 Nov 2021, 12:45.

  • #2
    In general, when Stata tells you things are not estimable, you will get unreliable results by forcing estimation with the -noestimcheck- option. There are exceptions, but your situation is not one of them.

    That said, I think you have not set up your regression properly to use -margins- anyway. I'm guessing from the names of your variables that things like parks_sq represent the square of parks (i.e. parks^2). If I have that right, you cannot use -margins- with regression, and you were, in a way, lucky that something turned out inestimable so you didn't just blunder on using meaningless results. If you want to use -margins-, you cannot use "homebrew" quadratic variables in your regression. Rather, you must use factor variable notation to create them. Instead of having var and var_sq, you must use c.var##c.var (N.B. ##, not #). Stata will then internally generate the linear and quadratic terms and include them in the regression. And, importantly, that will assure that -margins- knows that the quadratic term is a quadratic term and will handle it correctly in the calculations. (When you use var and var_sq, Stata thinks that these are two unrelated variables and therefore mishandles the calculations involving them.)

    There may be other problems not apparent from what you showed. The screenshot of your results is unreadable on my setup. Unreadability of screenshots is very common, which is why the Forum FAQ advises against using them. The effective way to show Stata results is to copy them from the Results window or your log file into the Forum editor and surround them by code delimiters. Read FAQ #12 if you are not familiar with code delimiters. (I imagine you aren't since you didn't use them for your code either.) Also, the code you show is evidently not your real code, because some of the variable names that appear in it are far longer than the 32 character limit on variable names in Stata. So I don't want to go too deep into trying to analyze your code, as I don't know in what ways it differs from the real thing.

    Comment


    • #3
      I have removed the variables you mentioned and just use google mobility data. to show that the problem is not with variables. I tried to build the intersection fixed effect regression model (day#busniss_policy) using xtreg where days is number for days after applying mask policy and busniss_policy is (0,1) indicates if the county apply busniss_policy or not. The results of regression as below where all coefficients are estimated except for last day (day 368)


      Code:
      xtset fips time
      
      replace  delta_mask= 0 if mask=="2077-12-31"
      
      summ delta_mask
      g days= delta_mask - r(min)
      
      
      
      summ days  if delta_mask == -7
      
      
      * used to find the index of -7 day after shifting and 30 days after policy 
      local true_neg1 = r(mean)
      
      summ days if delta_mask== 30
      
      
      g busniss_policy=business_delta_day
      
      
      replace busniss_policy=1 if busniss_policy>=0
      
      replace busniss_policy=0 if busniss_policy<0
      
      
      reghdfe cases_normed i.days#busniss_policy cases_normed_delay_14days cases_normed_delay_14days_growth residential workplaces transit_stations parks grocery_and_pharmacy retail_and_recreation  if days<=368 & days>=331&mask!="2077-12-31", absorb(fips time) vce(cluster fips) asis
      
      margins  days#busniss_policy, post
      Results:
      (dropped 166 singleton observations)
      (MWFE estimator converged in 24 iterations)
      note: 368.days#0b.busniss_policy omitted because of collinearity
      note: 368.days#1.busniss_policy omitted because of collinearity

      HDFE Linear regression Number of obs = 3,590
      Absorbing 2 HDFE groups F( 81, 587) = 3.24
      Statistics robust to heteroskedasticity Prob > F = 0.0000
      R-squared = 0.6365
      Adj R-squared = 0.5250
      Within R-sq. = 0.0593
      Number of clusters (fips) = 588 Root MSE = 0.4205

      (Std. err. adjusted for 588 clusters in fips)
      --------------------------------------------------------------------------------------------------
      | Robust
      cases_normed | Coefficient std. err. t P>|t| [95% conf. interval]
      ---------------------------------+----------------------------------------------------------------
      days#busniss_policy |
      331 0 | 0 (base)
      331 1 | -.3785024 .1439046 -2.63 0.009 -.6611329 -.0958719
      332 0 | -.0286351 .0810405 -0.35 0.724 -.1877999 .1305296
      332 1 | -.4687431 .1248702 -3.75 0.000 -.7139898 -.2234963
      333 0 | -.0529339 .0696404 -0.76 0.447 -.1897086 .0838409
      333 1 | -.4350848 .195188 -2.23 0.026 -.8184367 -.0517328
      334 0 | -.0123204 .0716729 -0.17 0.864 -.153087 .1284462
      334 1 | -.2812313 .1389139 -2.02 0.043 -.5540602 -.0084025
      335 0 | -.0948619 .0578722 -1.64 0.102 -.2085236 .0187998
      335 1 | -.4375989 .1179329 -3.71 0.000 -.6692206 -.2059771
      336 0 | .0984214 .0709704 1.39 0.166 -.0409654 .2378082
      336 1 | -.3576105 .136115 -2.63 0.009 -.6249422 -.0902787
      337 0 | -.0111905 .0620542 -0.18 0.857 -.1330657 .1106847
      337 1 | -.3619055 .124545 -2.91 0.004 -.6065136 -.1172974
      338 0 | .0315402 .0512197 0.62 0.538 -.069056 .1321364
      338 1 | -.2556062 .1190892 -2.15 0.032 -.4894989 -.0217135
      339 0 | .0159766 .0648646 0.25 0.806 -.1114183 .1433714
      339 1 | -.2983611 .1595379 -1.87 0.062 -.6116958 .0149736
      340 0 | -.0212477 .0693547 -0.31 0.759 -.1574612 .1149659
      340 1 | -.3429085 .1118587 -3.07 0.002 -.5626004 -.1232166
      341 0 | -.0154597 .058877 -0.26 0.793 -.1310949 .1001755
      341 1 | .0518958 .1552399 0.33 0.738 -.2529974 .3567891
      342 0 | .0872814 .0678902 1.29 0.199 -.0460559 .2206187
      342 1 | -.2198898 .1176075 -1.87 0.062 -.4508725 .0110928
      343 0 | .0559241 .0566958 0.99 0.324 -.0554272 .1672755
      343 1 | -.0154187 .2057291 -0.07 0.940 -.4194735 .3886361
      344 0 | .098108 .1115979 0.88 0.380 -.1210719 .3172878
      344 1 | -.209594 .103771 -2.02 0.044 -.4134017 -.0057863
      345 0 | .0253598 .0568927 0.45 0.656 -.0863783 .137098
      345 1 | -.2047456 .1220154 -1.68 0.094 -.4443855 .0348943
      346 0 | .0047448 .0730229 0.06 0.948 -.1386731 .1481626
      346 1 | -.2253762 .1352034 -1.67 0.096 -.4909175 .0401652
      347 0 | .0901131 .060661 1.49 0.138 -.0290259 .2092522
      347 1 | -.2708912 .1155353 -2.34 0.019 -.4978042 -.0439783
      348 0 | .0463957 .0603709 0.77 0.442 -.0721735 .164965
      348 1 | -.0800682 .1277212 -0.63 0.531 -.3309144 .170778
      349 0 | .1748163 .059026 2.96 0.003 .0588885 .2907441
      349 1 | -.1932883 .1363676 -1.42 0.157 -.4611162 .0745395
      350 0 | .1276891 .0639394 2.00 0.046 .0021112 .2532669
      350 1 | -.2461021 .1353546 -1.82 0.070 -.5119403 .0197362
      351 0 | -.0484437 .0612692 -0.79 0.429 -.1687773 .0718898
      351 1 | -.1128159 .1252921 -0.90 0.368 -.3588913 .1332594
      352 0 | .1978287 .0788838 2.51 0.012 .0428999 .3527574
      352 1 | -.3310455 .1166044 -2.84 0.005 -.5600581 -.1020328
      353 0 | .0318333 .062043 0.51 0.608 -.09002 .1536865
      353 1 | -.1871617 .1164498 -1.61 0.109 -.4158708 .0415473
      354 0 | .1856217 .0779045 2.38 0.018 .0326162 .3386272
      354 1 | -.1416514 .1101104 -1.29 0.199 -.3579096 .0746069
      355 0 | .0962708 .0568877 1.69 0.091 -.0154574 .2079989
      355 1 | -.2366667 .121115 -1.95 0.051 -.4745382 .0012048
      356 0 | .2624909 .1101126 2.38 0.017 .0462283 .4787534
      356 1 | -.2017364 .145319 -1.39 0.166 -.4871449 .0836721
      357 0 | .1301716 .0568979 2.29 0.023 .0184234 .2419198
      357 1 | -.1322139 .1097681 -1.20 0.229 -.3478 .0833721
      358 0 | .1050809 .0531327 1.98 0.048 .0007275 .2094343
      358 1 | -.1418137 .1130372 -1.25 0.210 -.3638203 .0801929
      359 0 | .165354 .0600988 2.75 0.006 .0473191 .2833888
      359 1 | -.1778536 .1022634 -1.74 0.083 -.3787002 .022993
      360 0 | .0910074 .061387 1.48 0.139 -.0295575 .2115722
      360 1 | -.1071111 .1158942 -0.92 0.356 -.3347288 .1205066
      361 0 | .207608 .0697663 2.98 0.003 .0705861 .3446299
      361 1 | -.2146253 .1224156 -1.75 0.080 -.4550511 .0258006
      362 0 | -.0021286 .073323 -0.03 0.977 -.1461361 .1418788
      362 1 | -.3290501 .1366439 -2.41 0.016 -.5974205 -.0606797
      363 0 | .0857311 .0621154 1.38 0.168 -.0362644 .2077265
      363 1 | -.140684 .0999765 -1.41 0.160 -.3370392 .0556711
      364 0 | .0868201 .0812561 1.07 0.286 -.0727681 .2464083
      364 1 | -.0915501 .0974802 -0.94 0.348 -.2830025 .0999022
      365 0 | .0078131 .0750609 0.10 0.917 -.1396075 .1552337
      365 1 | .0100225 .1258028 0.08 0.937 -.2370559 .2571009
      366 0 | .052421 .0706834 0.74 0.459 -.0864023 .1912442
      366 1 | -.0800325 .1515284 -0.53 0.598 -.3776364 .2175715
      367 0 | .0259653 .0645145 0.40 0.687 -.1007421 .1526726
      367 1 | -.0761031 .0832521 -0.91 0.361 -.2396115 .0874052
      368 0 | 0 (omitted)
      368 1 | 0 (omitted)
      |
      cases_normed_delay_14days | .1332996 .0566353 2.35 0.019 .0220671 .244532
      cases_normed_delay_14days_growth | -.002791 .0005906 -4.73 0.000 -.0039509 -.0016312
      residential | -.7144175 .5993666 -1.19 0.234 -1.891582 .4627466
      workplaces | -.3887375 .2089706 -1.86 0.063 -.7991586 .0216836
      transit_stations | .0438485 .0416414 1.05 0.293 -.0379358 .1256328
      parks | -.0080359 .0261777 -0.31 0.759 -.0594491 .0433774
      grocery_and_pharmacy | .1834313 .1586384 1.16 0.248 -.1281366 .4949993
      retail_and_recreation | -.0696244 .1034822 -0.67 0.501 -.2728649 .1336161
      _cons | .778438 .8210108 0.95 0.343 -.8340383 2.390914

      After trying margin command
      Code:
      margins  days#busniss_policy, post
      The results as follows:


      -------------------------------------------------------------------------------------
      | Delta-method
      | Margin std. err. z P>|z| [95% conf. interval]
      --------------------+----------------------------------------------------------------
      days#busniss_policy |
      331 0 | . (not estimable)
      331 1 | . (not estimable)
      332 0 | . (not estimable)
      332 1 | . (not estimable)
      333 0 | . (not estimable)
      333 1 | . (not estimable)
      334 0 | . (not estimable)
      334 1 | . (not estimable)
      335 0 | . (not estimable)
      335 1 | . (not estimable)
      336 0 | . (not estimable)
      336 1 | . (not estimable)
      337 0 | . (not estimable)
      337 1 | . (not estimable)
      338 0 | . (not estimable)
      338 1 | . (not estimable)
      339 0 | . (not estimable)
      339 1 | . (not estimable)
      340 0 | . (not estimable)
      340 1 | . (not estimable)
      341 0 | . (not estimable)
      341 1 | . (not estimable)
      342 0 | . (not estimable)
      342 1 | . (not estimable)
      343 0 | . (not estimable)
      343 1 | . (not estimable)
      344 0 | . (not estimable)
      344 1 | . (not estimable)
      345 0 | . (not estimable)
      345 1 | . (not estimable)
      346 0 | . (not estimable)
      346 1 | . (not estimable)
      347 0 | . (not estimable)
      347 1 | . (not estimable)
      348 0 | . (not estimable)
      348 1 | . (not estimable)
      349 0 | . (not estimable)
      349 1 | . (not estimable)
      350 0 | . (not estimable)
      350 1 | . (not estimable)
      351 0 | . (not estimable)
      351 1 | . (not estimable)
      352 0 | . (not estimable)
      352 1 | . (not estimable)
      353 0 | . (not estimable)
      353 1 | . (not estimable)
      354 0 | . (not estimable)
      354 1 | . (not estimable)
      355 0 | . (not estimable)
      355 1 | . (not estimable)
      356 0 | . (not estimable)
      356 1 | . (not estimable)
      357 0 | . (not estimable)
      357 1 | . (not estimable)
      358 0 | . (not estimable)
      358 1 | . (not estimable)
      359 0 | . (not estimable)
      359 1 | . (not estimable)
      360 0 | . (not estimable)
      360 1 | . (not estimable)
      361 0 | . (not estimable)
      361 1 | . (not estimable)
      362 0 | . (not estimable)
      362 1 | . (not estimable)
      363 0 | . (not estimable)
      363 1 | . (not estimable)
      364 0 | . (not estimable)
      364 1 | . (not estimable)
      365 0 | . (not estimable)
      365 1 | . (not estimable)
      366 0 | . (not estimable)
      366 1 | . (not estimable)
      367 0 | . (not estimable)
      367 1 | . (not estimable)
      368 0 | . (not estimable)
      368 1 | . (not estimable)


      Another question: How Can I plot the coefficient of results foe each group separately in same graph ( 0,1) groups of coefficients?

      Comment


      • #4
        Your problem is arising because of some colinearity. Notice that Stata warned you "note: 368.days#0b.busniss_policy omitted because of collinearity
        note: 368.days#1.busniss_policy omitted because of collinearity." Since the pattern we see is the omission of the two terms involving days == 368, which is the largest value of the date variable, the likely cause is that there is some other variable in your model that is constant over some groups of dates. This is the usual cause of this kind of colinearity. Based on the names of your variables, I would guess that the cases_normed_delay_14_days or cases_normed_delay_14days_growth variable (or perhaps both) is the root of the problem here. That sounds like something that might be constant within values of variable days, or groups of such values. But, perhaps you can identify the offending variable easily because you are familiar with the data. You need to remove that variable from the model. Then you will get estimates for all of the days, and the -margins- problem will go away once that is resolved. It is not possible for -margins- to identify marginal effects for variables that participate in a colinearity.

        How Can I plot the coefficient of results foe each group separately in same graph ( 0,1) groups of coefficients?
        I don't understand the question. Which groups are you referring to, and what exactly do you want to plot: what goes on the horizontal axis, and what goes on the vertical axis?

        Comment


        • #5
          Thank you very much for your reply as I spent days trying to solve this problem. after removing some variables that may cause this problem i am still getting omitted coefficient for the last day as follows:
          (dropped 166 singleton observations)
          (MWFE estimator converged in 24 iterations)
          note: 368.days#0b.busniss_policy omitted because of collinearity
          note: 368.days#1.busniss_policy omitted because of collinearity

          HDFE Linear regression Number of obs = 3,590
          Absorbing 2 HDFE groups F( 79, 587) = 2.18
          Statistics robust to heteroskedasticity Prob > F = 0.0000
          R-squared = 0.6279
          Adj R-squared = 0.5140
          Within R-sq. = 0.0370
          Number of clusters (fips) = 588 Root MSE = 0.4253

          (Std. err. adjusted for 588 clusters in fips)
          -------------------------------------------------------------------------------
          | Robust
          cases_normed | Coefficient std. err. t P>|t| [95% conf. interval]
          --------------+----------------------------------------------------------------
          days#|
          busniss_pol~y |
          331 1 | -.4099208 .1463507 -2.80 0.005 -.6973556 -.1224861
          332 0 | -.0280733 .0837722 -0.34 0.738 -.192603 .1364564
          332 1 | -.4984619 .1224785 -4.07 0.000 -.7390113 -.2579125
          333 0 | -.0616372 .0700387 -0.88 0.379 -.1991941 .0759198
          333 1 | -.5363874 .185835 -2.89 0.004 -.9013698 -.1714049
          334 0 | -.0225765 .0739121 -0.31 0.760 -.1677409 .1225878
          334 1 | -.3172599 .1398723 -2.27 0.024 -.5919711 -.0425487
          335 0 | -.0933705 .0597221 -1.56 0.118 -.2106655 .0239244
          335 1 | -.5004138 .1193204 -4.19 0.000 -.7347608 -.2660669
          336 0 | .0967768 .0701418 1.38 0.168 -.0409828 .2345363
          336 1 | -.4009202 .1458857 -2.75 0.006 -.6874417 -.1143988
          337 0 | -.0125092 .0618269 -0.20 0.840 -.1339381 .1089197
          337 1 | -.4015682 .1228618 -3.27 0.001 -.6428705 -.160266
          338 0 | .0315365 .0510951 0.62 0.537 -.0688151 .1318881
          338 1 | -.2958461 .1156456 -2.56 0.011 -.5229756 -.0687165
          339 0 | .042306 .0674217 0.63 0.531 -.0901112 .1747232
          339 1 | -.3720456 .1555316 -2.39 0.017 -.6775117 -.0665794
          340 0 | -.0115566 .0715844 -0.16 0.872 -.1521494 .1290362
          340 1 | -.3557411 .1119916 -3.18 0.002 -.5756941 -.135788
          341 0 | -.0185854 .0583593 -0.32 0.750 -.1332039 .096033
          341 1 | .0148648 .1622708 0.09 0.927 -.3038373 .333567
          342 0 | .1023682 .0698598 1.47 0.143 -.0348373 .2395738
          342 1 | -.2631451 .1163144 -2.26 0.024 -.4915882 -.0347021
          343 0 | .0740682 .0575279 1.29 0.198 -.0389175 .1870538
          343 1 | -.045251 .2053903 -0.22 0.826 -.4486403 .3581383
          344 0 | .1176535 .1101376 1.07 0.286 -.0986582 .3339652
          344 1 | -.2291802 .1020424 -2.25 0.025 -.4295929 -.0287674
          345 0 | .0408045 .0563465 0.72 0.469 -.0698607 .1514698
          345 1 | -.2384194 .1255983 -1.90 0.058 -.4850961 .0082573
          346 0 | .0222127 .0756599 0.29 0.769 -.1263844 .1708097
          346 1 | -.2546369 .1326608 -1.92 0.055 -.5151845 .0059107
          347 0 | .1153542 .0639572 1.80 0.072 -.0102585 .240967
          347 1 | -.3069842 .1106948 -2.77 0.006 -.5243902 -.0895781
          348 0 | .0553402 .0593864 0.93 0.352 -.0612955 .1719759
          348 1 | -.0976982 .1296248 -0.75 0.451 -.352283 .1568866
          349 0 | .1930237 .0584035 3.30 0.001 .0783184 .307729
          349 1 | -.2138118 .1374718 -1.56 0.120 -.4838084 .0561847
          350 0 | .1445166 .0630535 2.29 0.022 .0206787 .2683546
          350 1 | -.2743005 .128843 -2.13 0.034 -.52735 -.021251
          351 0 | -.0289425 .0635516 -0.46 0.649 -.1537586 .0958737
          351 1 | -.1453901 .1220631 -1.19 0.234 -.3851236 .0943435
          352 0 | .214769 .0776344 2.77 0.006 .062294 .367244
          352 1 | -.3472789 .1164588 -2.98 0.003 -.5760056 -.1185521
          353 0 | .0450266 .0625553 0.72 0.472 -.0778328 .167886
          353 1 | -.1798121 .1141795 -1.57 0.116 -.4040622 .0444379
          354 0 | .2014349 .0754679 2.67 0.008 .053215 .3496548
          354 1 | -.1796731 .1079783 -1.66 0.097 -.391744 .0323979
          355 0 | .1087534 .054784 1.99 0.048 .0011569 .2163499
          355 1 | -.2302023 .1196702 -1.92 0.055 -.4652361 .0048315
          356 0 | .2824935 .107707 2.62 0.009 .0709554 .4940316
          356 1 | -.2231089 .1538338 -1.45 0.148 -.5252405 .0790227
          357 0 | .1547178 .0556484 2.78 0.006 .0454236 .2640121
          357 1 | -.0782992 .1081413 -0.72 0.469 -.2906902 .1340919
          358 0 | .1349423 .0531275 2.54 0.011 .0305992 .2392854
          358 1 | -.1575049 .1127381 -1.40 0.163 -.3789242 .0639143
          359 0 | .1751728 .0602025 2.91 0.004 .0569343 .2934113
          359 1 | -.1489528 .0987957 -1.51 0.132 -.3429889 .0450833
          360 0 | .1098763 .0616988 1.78 0.075 -.011301 .2310537
          360 1 | -.1354763 .1137266 -1.19 0.234 -.3588368 .0878843
          361 0 | .2387945 .0745974 3.20 0.001 .0922842 .3853047
          361 1 | -.2109066 .1231149 -1.71 0.087 -.452706 .0308928
          362 0 | .002561 .076416 0.03 0.973 -.1475211 .152643
          362 1 | -.3449196 .1387402 -2.49 0.013 -.6174073 -.0724319
          363 0 | .1106431 .0626451 1.77 0.078 -.0123926 .2336789
          363 1 | -.1642916 .099942 -1.64 0.101 -.360579 .0319959
          364 0 | .1120981 .0751653 1.49 0.136 -.0355276 .2597238
          364 1 | -.1138568 .1051597 -1.08 0.279 -.3203919 .0926783
          365 0 | .0224863 .0770132 0.29 0.770 -.1287687 .1737414
          365 1 | .0063751 .1392956 0.05 0.964 -.2672033 .2799534
          366 0 | .0786756 .0677887 1.16 0.246 -.0544624 .2118135
          366 1 | -.1137175 .1497857 -0.76 0.448 -.4078987 .1804638
          367 0 | .0472342 .0662716 0.71 0.476 -.0829241 .1773926
          367 1 | -.0897144 .0820489 -1.09 0.275 -.2508596 .0714307
          368 0 | 0 (omitted)
          368 1 | 0 (omitted)
          |
          residential | -.6372152 .5779848 -1.10 0.271 -1.772385 .4979547
          workplaces | -.3516455 .2013581 -1.75 0.081 -.7471155 .0438246
          transit_sta~s | .0581689 .0414588 1.40 0.161 -.0232568 .1395946
          parks | -.0022952 .0263351 -0.09 0.931 -.0540177 .0494272
          grocery_and~y | .2286835 .1573574 1.45 0.147 -.0803686 .5377356
          retail_and_~n | -.0912527 .1100078 -0.83 0.407 -.3073095 .1248042
          _cons | .5892569 .7971742 0.74 0.460 -.976404 2.154918
          -------------------------------------------------------------------------------

          Absorbed degrees of freedom:
          -----------------------------------------------------+
          Absorbed FE | Categories - Redundant = Num. Coefs |
          -------------+---------------------------------------|
          fips | 588 588 0 *|
          time | 175 0 175 |
          -----------------------------------------------------+
          * = FE nested within cluster; treated as redundant for DoF computation

          .
          end of do-file



          How Can I plot the coefficient of results foe each group separately in same graph ( 0,1) groups of coefficients? in the attached results I want to plot the coefficient of regression using coeplot. you see two groups of coefficient the first one with business policy=0 and the other with business policy=1. when i plot the previous coefficient it plotted all together without any distinguish of colors between groups.
          Last edited by amera amery; 03 Nov 2021, 20:03.

          Comment


          • #6
            I think I see the problem. The colinearity is probably arising with the absorbed effects, fips and time. As I am not entirely sure what all of these variables are, I can't be entirely sure of the details, but I suspect there may be colinearity between the variables days and time, or perhaps there is an issue of policy being constant within fips. To know in more detail, I would need to work with example data. If you want me to do that, please post back using the -dataex- command to show an example. Please be sure your example exhibits this same problem. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

            As for your other question, I do not use -coefplot- and know very little about it, so I can't help you with that. If somebody else following this thread knows the answer I hope they will chime in. If that does not happen within, say, 24 hours, I suggest starting a new thread with just that question.

            Comment


            • #7
              Thank you. As my dataset has 1 million records I just collected 1000 in the attached do file. of them and change some numbers in the code. but still have the same problem.

              Code:
              replace  delta_mask= 0 if mask=="2077-12-31"
              
              summ delta_mask
              g days= delta_mask - r(min)
              
              
              
              summ days  if delta_mask == -7
              
              
              * used to find the index of -7 day after shifting and 30 days after policy 
              local true_neg1 = r(mean)
              
              summ days if delta_mask== 30
              
              
              g busniss_policy=business_delta_day
              
              
              replace busniss_policy=1 if busniss_policy>=0
              
              replace busniss_policy=0 if busniss_policy<0
              
              
              reghdfe cases_normed i.days#busniss_policy  residential workplaces transit_stations parks grocery_and_pharmacy retail_and_recreation  if days<=36& days>=0&mask!="2077-12-31", absorb(fips time)  
              
              margins  days#busniss_policy, post
              fips: county identification number
              time: time series for each county and it is the same for all counties.
              I used fips and time in fixed effect regression
              delta_mask: number of days from applying mask policy >0 means county applied policy <0 means did not apply the policy.
              business_delta_day:number of days from applying businesspolicy >0 means county applied policy <0 means did not apply the policy.
              Attached Files

              Comment


              • #8
                Thank you.

                The data example you sent has busniss_policy = 0 in all observations, which is an additional complication that, I imagine, does not obtain in the full data set. But you should verify that. But what I think is the source of your problem is that the variable days is completely determined by the combination of time and fips. Here is the proof of the colinearity:

                Code:
                . regress days i.time i.fips if days<=36& days>=0&mask!="2077-12-31"
                
                      Source |       SS           df       MS      Number of obs   =       950
                -------------+----------------------------------   F(80, 869)      =         .
                       Model |  107626.316        80  1345.32895   Prob > F        =         .
                    Residual |           0       869           0   R-squared       =    1.0000
                -------------+----------------------------------   Adj R-squared   =    1.0000
                       Total |  107626.316       949  113.410238   Root MSE        =         0
                
                ------------------------------------------------------------------------------
                        days | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                -------------+----------------------------------------------------------------
                        time |
                        172  |          1          .        .       .            .           .
                        173  |          2          .        .       .            .           .
                        174  |          3          .        .       .            .           .
                        175  |          4          .        .       .            .           .
                        176  |          5          .        .       .            .           .
                        177  |          6          .        .       .            .           .
                        178  |          7          .        .       .            .           .
                        179  |          8          .        .       .            .           .
                        180  |          9          .        .       .            .           .
                        181  |         10          .        .       .            .           .
                        182  |         11          .        .       .            .           .
                        183  |         12          .        .       .            .           .
                        184  |         13          .        .       .            .           .
                        185  |         14          .        .       .            .           .
                        186  |         15          .        .       .            .           .
                        187  |         16          .        .       .            .           .
                        188  |         17          .        .       .            .           .
                        189  |         18          .        .       .            .           .
                        190  |         19          .        .       .            .           .
                        191  |         20          .        .       .            .           .
                        192  |         21          .        .       .            .           .
                        193  |         22          .        .       .            .           .
                        194  |         23          .        .       .            .           .
                        195  |         24          .        .       .            .           .
                        196  |         25          .        .       .            .           .
                        197  |         26          .        .       .            .           .
                        198  |         27          .        .       .            .           .
                        199  |         28          .        .       .            .           .
                        200  |         29          .        .       .            .           .
                        201  |         30          .        .       .            .           .
                        202  |         31          .        .       .            .           .
                        203  |         32          .        .       .            .           .
                        204  |         33          .        .       .            .           .
                        205  |         34          .        .       .            .           .
                        206  |         35          .        .       .            .           .
                        207  |         36          .        .       .            .           .
                        208  |         37          .        .       .            .           .
                        209  |         38          .        .       .            .           .
                        210  |         39          .        .       .            .           .
                        211  |         40          .        .       .            .           .
                        212  |         41          .        .       .            .           .
                        213  |         42          .        .       .            .           .
                        214  |         43          .        .       .            .           .
                        215  |         44          .        .       .            .           .
                        216  |         45          .        .       .            .           .
                        217  |         46          .        .       .            .           .
                        218  |         47          .        .       .            .           .
                        219  |         48          .        .       .            .           .
                        220  |         49          .        .       .            .           .
                        221  |         50          .        .       .            .           .
                        222  |         51          .        .       .            .           .
                        223  |         52          .        .       .            .           .
                        224  |         53          .        .       .            .           .
                        225  |         54          .        .       .            .           .
                        226  |         55          .        .       .            .           .
                             |
                        fips |
                       1003  |   8.66e-14          .        .       .            .           .
                       1005  |   8.64e-14          .        .       .            .           .
                       1007  |   8.64e-14          .        .       .            .           .
                       1009  |   8.65e-14          .        .       .            .           .
                       1011  |   8.65e-14          .        .       .            .           .
                       1013  |   8.51e-14          .        .       .            .           .
                       1015  |   8.64e-14          .        .       .            .           .
                       1017  |   8.65e-14          .        .       .            .           .
                       1019  |   8.65e-14          .        .       .            .           .
                       1021  |   8.65e-14          .        .       .            .           .
                       1023  |   8.65e-14          .        .       .            .           .
                       1025  |   8.63e-14          .        .       .            .           .
                       1027  |   8.66e-14          .        .       .            .           .
                       1029  |   8.64e-14          .        .       .            .           .
                       1031  |   8.64e-14          .        .       .            .           .
                       1033  |   8.64e-14          .        .       .            .           .
                       1035  |   8.65e-14          .        .       .            .           .
                       1037  |   8.66e-14          .        .       .            .           .
                       1039  |   8.43e-14          .        .       .            .           .
                       1041  |   8.65e-14          .        .       .            .           .
                       1043  |   8.65e-14          .        .       .            .           .
                       1045  |   8.62e-14          .        .       .            .           .
                       1047  |         19          .        .       .            .           .
                       1049  |   8.61e-14          .        .       .            .           .
                       1051  |   8.44e-14          .        .       .            .           .
                             |
                       _cons |        -19          .        .       .            .           .
                ------------------------------------------------------------------------------
                Note the R2 = 1. This is exact colinearity. (The 8.64e-14 coefficients are zeros with some rounding error--if you juggle these results you will see that there is an exact relationship days = time-190, except in fips 1047, where days = time - 171.) So you cannot use the days variable and also absorb both time and fips.

                My first thought is to wonder why are the time and days variables so tightly related to each other (and perfectly related if we take fips into account as well). Is one of them incorrect? It is unusual to have two variables in the data set that are so strongly related to each other. Usually it's because one of them is a mistake. If they are both correct, then you are going to have to omit one of them from the model. (Or you might try removing fips instead, your data set is so large that even in the presence of such strong colinearity between days and time that you might get stable results if fips were taken out of the picture, but I doubt it since everything would then hinge on the slightly different relationship between days and time seen in fips 1047.)
                Last edited by Clyde Schechter; 03 Nov 2021, 23:31.

                Comment


                • #9
                  I am using the fixed effect regression and I have generated time (date-"2020-1-1") to be able to use it as a time series in fixed effect regression as this regression asked about time variable to be specified. my thought is that the colinearity is exist among independent variable in regression and I did not use time as independent variable in regression to get the colinearity problem. but after removing time from absorb function still get omitted for last day with buinsess_policy=1 as follows:
                  Code:
                  
                  (dropped 92 singleton observations)
                  (MWFE estimator converged in 1 iterations)
                  note: 368.days#1.busniss_policy omitted because of collinearity
                  
                  HDFE Linear regression                            Number of obs   =      3,664
                  Absorbing 1 HDFE group                            F(  80,   2990) =       1.48
                                                                    Prob > F        =     0.0041
                                                                    R-squared       =     0.5612
                                                                    Adj R-squared   =     0.4624
                                                                    Within R-sq.    =     0.0380
                                                                    Root MSE        =     0.4730
                  
                  -------------------------------------------------------------------------------
                   cases_normed | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                  --------------+----------------------------------------------------------------
                           days#|
                  busniss_pol~y |
                         331 1  |   -.183647    .184291    -1.00   0.319     -.544997    .1777029
                         332 0  |  -.0108646   .0784753    -0.14   0.890    -.1647357    .1430065
                         332 1  |  -.3288637   .1661537    -1.98   0.048    -.6546508   -.0030767
                         333 0  |  -.0737479   .0779222    -0.95   0.344    -.2265345    .0790387
                         333 1  |  -.3521921    .187075    -1.88   0.060    -.7190008    .0146166
                         334 0  |  -.0353539   .0810662    -0.44   0.663     -.194305    .1235972
                         334 1  |   -.287462   .2102734    -1.37   0.172    -.6997571    .1248331
                         335 0  |  -.1327006   .0786884    -1.69   0.092    -.2869896    .0215883
                         335 1  |  -.4236115   .1943978    -2.18   0.029    -.8047785   -.0424444
                         336 0  |    .059865    .078678     0.76   0.447    -.0944036    .2141335
                         336 1  |   -.300042   .1688129    -1.78   0.076    -.6310432    .0309592
                         337 0  |  -.0118283   .0835899    -0.14   0.887    -.1757278    .1520712
                         337 1  |  -.2329834   .1706959    -1.36   0.172    -.5676767    .1017098
                         338 0  |   .0401325   .0794825     0.50   0.614    -.1157134    .1959783
                         338 1  |   .0085674   .1757388     0.05   0.961    -.3360138    .3531486
                         339 0  |   .0916985   .0810704     1.13   0.258    -.0672609     .250658
                         339 1  |  -.1855247   .1708097    -1.09   0.278    -.5204412    .1493918
                         340 0  |  -.0389724   .0809749    -0.48   0.630    -.1977444    .1197997
                         340 1  |  -.1767039   .1684643    -1.05   0.294    -.5070217    .1536138
                         341 0  |  -.0612233   .0816568    -0.75   0.453    -.2213324    .0988859
                         341 1  |  -.0515542    .178749    -0.29   0.773    -.4020378    .2989293
                         342 0  |   .0407878   .0803586     0.51   0.612    -.1167761    .1983516
                         342 1  |  -.2141028   .1805367    -1.19   0.236    -.5680915    .1398859
                         343 0  |   .0427721   .0771287     0.55   0.579    -.1084585    .1940027
                         343 1  |   .0626085    .156433     0.40   0.689    -.2441187    .3693357
                         344 0  |   .1319646   .0823549     1.60   0.109    -.0295134    .2934425
                         344 1  |  -.1459327   .1712621    -0.85   0.394    -.4817362    .1898707
                         345 0  |    .029413   .0760691     0.39   0.699    -.1197401    .1785662
                         345 1  |  -.1778338   .2078138    -0.86   0.392    -.5853063    .2296387
                         346 0  |   .0440757   .0784369     0.56   0.574      -.10972    .1978714
                         346 1  |  -.0987653   .1760017    -0.56   0.575     -.443862    .2463314
                         347 0  |    .053933   .0781458     0.69   0.490     -.099292    .2071579
                         347 1  |   -.193008   .1724892    -1.12   0.263    -.5312175    .1452016
                         348 0  |  -.0133792   .0798774    -0.17   0.867    -.1699995    .1432411
                         348 1  |   .0940962   .1667075     0.56   0.572    -.2327768    .4209691
                         349 0  |   .1277307   .0762846     1.67   0.094    -.0218449    .2773062
                         349 1  |  -.2452425   .1782802    -1.38   0.169    -.5948068    .1043219
                         350 0  |   .0637541    .078787     0.81   0.418    -.0907281    .2182363
                         350 1  |  -.1804647   .1800949    -1.00   0.316     -.533587    .1726577
                         351 0  |  -.0338998   .0792428    -0.43   0.669    -.1892758    .1214761
                         351 1  |  -.4057417   .1628739    -2.49   0.013    -.7250981   -.0863854
                         352 0  |   .1553104   .0798732     1.94   0.052    -.0013016    .3119225
                         352 1  |  -.1738054   .1684738    -1.03   0.302    -.5041417    .1565309
                         353 0  |   .0110072   .0805764     0.14   0.891    -.1469836    .1689979
                         353 1  |  -.0547025   .1841086    -0.30   0.766    -.4156948    .3062898
                         354 0  |   .1398289   .0792685     1.76   0.078    -.0155975    .2952553
                         354 1  |  -.1390049   .1738561    -0.80   0.424    -.4798945    .2018848
                         355 0  |   .0022844   .0788798     0.03   0.977    -.1523797    .1569485
                         355 1  |  -.2779353   .1684323    -1.65   0.099    -.6081901    .0523195
                         356 0  |   .1665103   .0794925     2.09   0.036     .0106448    .3223758
                         356 1  |  -.1605142    .176079    -0.91   0.362    -.5057624     .184734
                         357 0  |   .0059194   .0826253     0.07   0.943    -.1560889    .1679277
                         357 1  |  -.3000363   .1795686    -1.67   0.095    -.6521269    .0520542
                         358 0  |   .1036955   .0778141     1.33   0.183    -.0488791    .2562701
                         358 1  |  -.1165501   .1628458    -0.72   0.474    -.4358512     .202751
                         359 0  |   .1109954   .0784887     1.41   0.157    -.0429019    .2648928
                         359 1  |   .0069488   .1638173     0.04   0.966    -.3142571    .3281548
                         360 0  |   .0192964   .0865679     0.22   0.824    -.1504422     .189035
                         360 1  |   -.078074   .1581449    -0.49   0.622    -.3881578    .2320098
                         361 0  |   .1442134    .080101     1.80   0.072    -.0128453    .3012721
                         361 1  |  -.1148409   .1672719    -0.69   0.492    -.4428205    .2131388
                         362 0  |  -.0934121   .0840626    -1.11   0.267    -.2582385    .0714144
                         362 1  |  -.1703662   .1837668    -0.93   0.354    -.5306883    .1899559
                         363 0  |  -.0299809   .0828708    -0.36   0.718    -.1924704    .1325086
                         363 1  |  -.1385221   .1795026    -0.77   0.440    -.4904833     .213439
                         364 0  |  -.0125648   .0838218    -0.15   0.881    -.1769189    .1517894
                         364 1  |   .0258663   .1679649     0.15   0.878    -.3034721    .3552047
                         365 0  |  -.1051515    .079917    -1.32   0.188    -.2618494    .0515463
                         365 1  |  -.0949899   .1736825    -0.55   0.584    -.4355391    .2455593
                         366 0  |   .0565542    .085706     0.66   0.509    -.1114945    .2246029
                         366 1  |  -.1821631   .1771512    -1.03   0.304    -.5295136    .1651875
                         367 0  |  -.0518685   .0845795    -0.61   0.540    -.2177085    .1139715
                         367 1  |   -.083387   .1756926    -0.47   0.635    -.4278776    .2611037
                         368 0  |  -.1104242    .088316    -1.25   0.211    -.2835905     .062742
                         368 1  |          0  (omitted)
                                |
                    residential |  -.1105294   .5132284    -0.22   0.830    -1.116846    .8957872
                     workplaces |  -.2910593   .2113937    -1.38   0.169    -.7055511    .1234324
                  transit_sta~s |    .083278   .0464314     1.79   0.073    -.0077628    .1743188
                          parks |   .0034286   .0229842     0.15   0.881    -.0416378    .0484949
                  grocery_and~y |    .123441   .1316366     0.94   0.348    -.1346666    .3815485
                  retail_and_~n |  -.0926652   .1215411    -0.76   0.446    -.3309779    .1456475
                          _cons |    .099166   .7050186     0.14   0.888    -1.283205    1.481537
                  -------------------------------------------------------------------------------
                  
                  Absorbed degrees of freedom:
                  -----------------------------------------------------+
                   Absorbed FE | Categories  - Redundant  = Num. Coefs |
                  -------------+---------------------------------------|
                          fips |       594           0         594     |
                  -----------------------------------------------------+
                  
                  . 
                  end of do-file
                  do you think having . (null) values of some google mobility data may cause this problem?

                  Yes the data I have uploaded all Buisness_policy =0 but it is not the case in the whole data set.

                  Comment


                  • #10
                    This is a different result and it is not a problem. Notice that this time there is only one coefficient omtited, not, as before, two. I will admit that I am puzzled why it is the last one that is omitted, since I normally expect Stata to remove the first. But that doesn't actually matter. The point is that there is no longer any problematic colinearity: what you are seeing is just the routine omission of one base category. And if you run -margins days#busniss_policy- after this, you will get estimates.

                    Comment


                    • #11
                      The results are different because i am using the whole dataset not just the one i sent This is not the routine omission as the routine omission happened at day 331 0. so two values are omitted.

                      Even I tried with just keep regression with one independent variable i.days#buisness_policy but got the same problem.
                      Last edited by amera amery; 04 Nov 2021, 11:15.

                      Comment


                      • #12
                        Well, your example data set produces very similar looking results, and -margins- does give results afterwards. Notice that while 368 1 was omitted, 368 0 was not. That's a key difference. If you still had a complete colinearity going on with the days variable, both 368 1 and 368 0 would have been omitted. Have you tried running -margins- after the regression in #9. I believe it will work.

                        Even I tried with just keep regression with one independent variable i.days#buisness_policy and got the same problem.
                        Right. This just confirms what I have asserted before: to the extent you have problems, it is with the variables days, time and fips. The other variables are not part of the problem.

                        Comment


                        • #13
                          the regression after removing time. the days#busniss variable is an intersection variable to study days with busniss_policy.

                          Code:
                          reghdfe cases_normed i.days#busniss_policy cases_normed_delay_14days cases_normed_delay_14days_growth residential workplaces transit_stations parks grocery_and_pharmacy retail_and_recreation  if days<=368 & days>=331&mask!="2077-12-31", absorb(fips ) vce(cluster fips)
                          and still can not get the margin estimation as it is not estimable for all coefficient. The things I noticed that if I removed the condition mask!="2077-12-31" I will get good results without any omitted values. but I should include it in my regression as this condition mean that include the counties that applied the mask the value of mask=2077-12-31" means it did not applied the policy and it is beyond of our interest.
                          Last edited by amera amery; 04 Nov 2021, 16:25.

                          Comment


                          • #14
                            I see this post as well on your website. They mentioned that this problem may because of lake of combination data? So when I removed the condition we will have enough data then nothing is omitted? Do you think this is the problem?!!!

                            In the documentation of the margins command in the Stata Base Reference Manual Release 13 you will see on page 1185 "Estimability of Margins" which discusses the problem with estimating margins when some combinations of the variables lack data.

                            With that said, the following will ignore the estimability issues and provide margins, leaving it to you to determine if they make sense within the limitations discussed by the cited passage.

                            Comment


                            • #15
                              I see this answer posted on your website. They mentioned that this problem because of lake of combination data? So when I removed the condition we will have enough data then nothing is omitted? Do you think this is the problem?!!!


                              ""In the documentation of the margins command in the Stata Base Reference Manual Release 13 you will see on page 1185 "Estimability of Margins" which discusses the problem with estimating margins when some combinations of the variables lack data.

                              With that said, the following will ignore the estimability issues and provide margins, leaving it to you to determine if they make sense within the limitations discussed by the cited passage.""

                              Comment

                              Working...
                              X