Announcement

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

  • Plotting moderating effects: 1. Margin plots empty output issue; 2. Solutions for 3-way margin plots with c. and i.

    Dear Stata experts,

    please help me to find a mistake in my code. It worked fine just 3 days ago but then stopped for no obvious for me reason (have probably gone through my code for at least 10 times in search for a failure... now you are my last hope to find the mistake).
    And sorry for putting out here such a complex code, but it could be relevant to see the whole code as I am not sure what exactly is causing the issue...

    FYI: I have updated Stata and installed asdocx package around the same time the issue has started to appear. Not sure though that this could be somehow connected...


    About my dataset: 20 years, ca. 7 000 observations, ca. 800 companies.

    I am using loops to run and compare different models to check for stable results + to do plots to visualize the moderating effects. Depending on the model option, the effect is between related_share_w (my key IV) and (a) category variable, (b) continuous variable, (c) 2 category variables, (d) a category and continuous variable.

    Would be great if you can advise me on the following:
    1. how to fix the code to get the plots for (a) and (b) work again?
    2. how to write properly the code to plot 3-way effects of (c) and (d)?



    Current code:
    Code:
    xtset gvkey fyear
    
    local DVs "tobinq3_ln" // could be switched to several - to simplify for now just 1
    local controls "c.emp_ln c.roa_w c.total_divers_w"
    local EXTRAs "c.mint_w" // could be switched to several - to simplify for now just 1
    
    local Model3 "i.firstmover_related_sic4 i.related_serv_entry c.related_share_w##c.related_share_w##c.related_invest_firm_w c.related_share_w##c.related_share_w##c.serv_share_w c.related_share_w##c.related_share_w##i.firstmover_related_years c.related_share_w##c.related_share_w##i.related_serv_entry_years c.related_share_w##c.related_share_w##c.related_speed_w c.related_share_w##c.related_share_w##c.rslack2_w c.related_share_w##c.related_share_w##c.advint_w c.related_share_w##c.related_share_w##c.mgrowth_w c.related_share_w##c.related_share_w##c.mdynamism1_w c.related_share_w##c.related_share_w##c.mmunificence_w"
    
    local Model4 "i.firstmover_related_sic4 c.related_share_w#c.related_speed_w#c.related_invest_firm_w c.rslack2_w c.advint_w c.mgrowth_w c.mdynamism1_w c.mmunificence_w c.related_share_w##c.related_share_w##c.related_invest_firm_w c.related_share_w##c.related_share_w##c.serv_share_w c.related_share_w##c.related_share_w##i.firstmover_related_years c.related_share_w##c.related_share_w##i.related_serv_entry_years c.related_share_w##c.related_share_w##c.related_speed_w"
    
    // here further models from Model1 till Model 13 are stated, Models 3 and 4 are provided as one of them as an example
    
    local ModelN = 13
    
    local cMEs "c.related_invest_firm_w c.serv_share_w c.related_speed_w c.rslack2_w c.advint_w c.mgrowth_w c.mdynamism1_w c.mmunificence_w"
    local iMEs "firstmover_related_years related_serv_entry_years"
    
    foreach DV of local DVs {
        foreach EXTRA of local EXTRAs {
        local Mymodel "FEr-yd-6"
        forv i = 1/`ModelN' {
     
        xtreg `DV' `Model`i'' `controls' `EXTRA' i.fyear, fe vce (robust) // thats were the regression is defined
        outreg2 using "Regression_results", append excel dec(3) label(insert) ctitle(`DV', `EXTRA', `Mymodel', Model `i') drop(i.fyear) sideway noparen addtext(Company FE, YES, Year FE, YES) e(all) // up till here everything works well...
        
    ***** Creating margin plots for the continious MEs (above point (b)), e.g. for c.related_share_w##c.related_share_w##c.related_invest_firm_w - this worked perfectly just 3 days ago and suddenly started to produce empty graphs instead (the axes, legend are there - just the graphs themselves are missing!)
            summarize related_share_w
            local MyMin = max((r(mean) - r(sd)),r(min))
            local MyMax = min((r(mean) + r(sd)),r(max))
            local Grid = (`MyMax'-`MyMin')/10
        
            foreach cME of local cMEs {
            quietly summarize `cME'
            local MyMin2 = max((r(mean) - r(sd)),r(min))
            local MyMax2 = min((r(mean) + r(sd)),r(max))
            local Grid2 = (`MyMax2'-`MyMin2')/2
            
            // creating first margin plot - Modearting effect
            capture quietly margins, at(c.related_share_w=(`MyMin' (`Grid') `MyMax') `cME'=(`MyMin2' (`Grid2') `MyMax2'))
            capture marginsplot, recast(line) noci title("Moderating effect of `cME'") xtitle("Service relatedness") ytitle("Firm performance: `DV'") xlabel(, angle(45) format(%5.2f)) plot1opts(lcolor(black)) plot2opts(lcolor(gs6) lpattern("--")) legend(on order(1 "low level `cME'" 2 "medium level `cME'" 3 "high level `cME'")) name(main)
            
            // creating second margin plot - Marginal effect
            capture quietly margins, dydx(`cME') at(c.related_share_w=(`MyMin' (`Grid') `MyMax'))
            capture marginsplot, recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) title("Average marginal effects of `cME'") xtitle("Service relatedness") ytitle("Firm performance: `DV'") xlabel(, angle(45) format(%5.2f)) name(diff)
            
            // combining the plots together
            capture graph combine main diff, xsize(6.5) ysize(2.7) iscale(.8) name(comb)
            capture graph export "`DV', `Mymodel', Model_`i' - Effect of `cME' on Service relatedness.png", width(6000) replace
            capture graph close comb
            graph drop _all        
            }
            
    ***** Creating margin plots for 3-way effects with one being category variable (above point (d)), e.g. for c.related_share_w##c.related_invest_firm_w##i.firstmover_related_years - this does NOT work within the loop - only if used separately outside any loops
            
            summarize related_invest_firm_w
            local MyMin4 = max((r(mean) - r(sd)),r(min))
            local MyMax4 = min((r(mean) + r(sd)),r(max))
            local Grid4 = (`MyMax4'-`MyMin4')/2
            local mid4 = (`MyMax4'-`MyMin4')/2 + `MyMin4'
            
            capture marginscontplot2 related_share_w related_invest_firm_w, var1(10) var2_spec(`MyMin4' `mid4' `MyMax4') at(i.`iME') areaopts(bla (format(%5.2f)) yla("TobinQ", format(%5.2f)) xla("Service relatedness", format(%5.2f))) // I liked marginscontplot2 for this more, but happy to here if somebody has a nicer solution here. Also, appreciate if you could give me a hint how to manipulate the legend lables and format here, the normal graphs functions seem not to work with it.
    
    capture graph export "`DV', `Mymodel', Model_`i' - Three-way effect with related invest and `iME'.png", replace
        graph close
        graph drop _all
            
      ***** Creating margin plots for category MEs (above point (a)), e.g. for c.related_share_w##c.related_share_w##i.firstmover_related_years:
       // creating first margin plot - Moderating effect
            foreach iME of local iMEs {
            capture quietly margins i.`iME', at(c.related_share_w=(`MyMin' (`Grid') `MyMax'))
            capture marginsplot, recast(line) noci title("Moderating effect of `iME'") xtitle("Service relatedness") ytitle("Firm performance: `DV'") xlabel(, angle(45) format(%5.2f)) plot1opts(lcolor(black)) plot2opts(lcolor(gs6) lpattern("--")) name (main)
            
            // creating second margin plot - Marginal effect
            capture quietly margins, dydx(`iME') at(c.related_share_w=(`MyMin' (`Grid') `MyMax'))
            capture marginsplot, recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) title("Average marginal effects of `iME'") xtitle("Service relatedness") ytitle("Firm performance: `DV'") xlabel(, angle(45) format(%5.2f)) name(diff)
                    
            // combining the plots together
            capture graph combine main diff, xsize(6.5) ysize(2.7) iscale(.8) name(comb)
            capture graph export "`DV', `Mymodel', Model_`i' - Effect of `iME' on Service relatedness.png", width(6000) replace
            capture graph close comb
            graph drop _all
            }
        }
    }
    }
    And for the 3-way effect (c) - when 3 category variables interact (e.g. c.related_share_w#c.related_speed_w#c.related_inve st_firm_w) - I came up with following solution of creating separate graphs for specific values of one of the variables... but am not super happy with the visuals as I experience challenge of manipulating marginscontplot2 function to format the legend / axes nicely. Do you have a better solution that ideally also works within loops?

    Code:
    summarize related_share_w
            local MyMin = max((r(mean) - r(sd)),r(min))
            local MyMax = min((r(mean) + r(sd)),r(max))
            local Grid = (`MyMax'-`MyMin')/10
        
        summarize related_invest_firm_w
            local MyMin4 = max((r(mean) - r(sd)),r(min))
            local MyMax4 = min((r(mean) + r(sd)),r(max))
            local Grid4 = (`MyMax4'-`MyMin4')/2
            local riv (`MyMin4' `Grid4' `MyMax4')
            
            summarize related_speed_w
            local MyMin5 = max((r(mean) - r(sd)),r(min))
            local MyMax5 = min((r(mean) + r(sd)),r(max))  
            local Grid5 = (`MyMax5'-`MyMin5')/2
        
    marginscontplot2 related_share_w related_speed_w, var1(10) var2(3) at(related_invest_firm_w = `MyMin4') areaopts(bla (format(%5.2f)) yla("TobinQ", format(%5.2f)) xla("Service relatedness", format(%5.2f))) lineopts(legend(1 "slow related serv speed" 2 "medium related serv speed" 3 "fast related serv speed")) // not clear how to manipulate the legend lables and format
    graph export "Three-way effect - related invest = low.png", replace
        graph close
        graph drop _all
        
    marginscontplot2 related_share_w related_speed_w, var1(10) var2(3) at(related_invest_firm_w = `MyMin4') ci combopts(ycommon xcommon) areaopts(xla(, format(%5.2f)) ytitle("TobinQ") xtitle("Service relatedness"))
    graph export "Three-way effect with ci - related invest = low.png", replace
        graph close
        graph drop _all
    
    marginscontplot2 related_share_w related_speed_w, var1(10) var2(3) at(related_invest_firm_w = `Grid4') areaopts(bla (format(%5.2f)) yla("TobinQ", format(%5.2f)) xla("Service relatedness", format(%5.2f)))
    graph export "Three-way effect - related invest = mean.png", replace
        graph close
        graph drop _all
        
    marginscontplot2 related_share_w related_speed_w, var1(10) var2(3) at(related_invest_firm_w = `Grid4') ci combopts(ycommon xcommon) areaopts(xla(, format(%5.2f)) ytitle("TobinQ") xtitle("Service relatedness"))
    graph export "Three-way effect with ci - related invest = mean.png", replace
        graph close
        graph drop _all
    
        marginscontplot2 related_share_w related_speed_w, var1(10) var2(3) at(related_invest_firm_w = `MyMax4') areaopts(bla (format(%5.2f)) yla("TobinQ", format(%5.2f)) xla("Service relatedness", format(%5.2f)))
    graph export "Three-way effect - related invest = high.png", replace
        graph close
        graph drop _all
        
    marginscontplot2 related_share_w related_speed_w, var1(10) var2(3) at(related_invest_firm_w = `MyMax4') ci combopts(ycommon xcommon) areaopts(xla(, format(%5.2f)) ytitle("TobinQ") xtitle("Service relatedness"))
    graph export "Three-way effect with ci - related invest = high.png", replace
        graph close
        graph drop _all
    Data example:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(related_share_w related_invest_firm_w serv_share_w) byte(related_serv_entry_years firstmover_related_years) float(related_speed_w rslack2_w advint_w mgrowth_w mdynamism1_w mmunificence_w emp_ln roa_w total_divers_w mint_w tobinq3_ln)
    .5 .030393185        .5 2 0  .3228407 .50553256   .09835758  .4078782 . . 1.0807877    .247941        0  .10162693 1.631337
     0          0         0 0 0         0   .401124   .10396002  .0985591 . . 1.1693814 .025326524        0  .10314787        .
    .5  .02390977        .5 2 2 .01662697 .17948684  .003808496 -.1843253 . . 1.9315214  .11211377        0          .  .690114
    .5 .014010232        .5 2 0 -.3077015  .5669612   .10396002  .0985591 . . .03633193  -.3270054        0 .011902187 .3908798
     0          . .26832914 2 0 -.4882525  .4053705 .0039266297  .5676779 . .  .3653373 .074105754 .5815899  .29764232 .3269372
    end
    Appreciate a lot any feedback and hints on how the code can be fixed to make the plots show up!

    This forum was my source of inspiration multiple times (dear Statalist community, you are fantastic! thanks a lot!). May this discussion and my code help somebody as well who is dealing with similar issues Hope we can find a solution together here.
    Last edited by Kseniya Levykina; 18 Feb 2022, 16:20.

  • #2
    Here is how the empty plot output look like:
    Click image for larger version

Name:	tobinq3_ln, FEr-yd-6, Model_3 - Effect of c.mgrowth_w on Service relatedness.png
Views:	1
Size:	483.7 KB
ID:	1650904


    Comment


    • #3
      Your question is very long and the problems are not fully reproducible. For similar questions in the future, I would advise you to consider splitting them into several questions/ posts. You are using marginscontplot2 from SSC (FAQ Advice #12). For #1, it is not clear what issues you are facing. My suggestion is that you remove the capture commands from the codes so that Stata can display the error messages. Then you can post these errors in case you are not able to resolve them. For #2, if your issue is on how to manipulate the legend labels, the following (which modifies your data example to make the problem reproducible) illustrates:

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float(related_share_w related_invest_firm_w serv_share_w) byte(related_serv_entry_years firstmover_related_years) float(related_speed_w rslack2_w advint_w mgrowth_w mdynamism1_w mmunificence_w emp_ln roa_w total_divers_w mint_w tobinq3_ln)
      .5 .030393185        .5 2 0  .3228407 .50553256   .09835758  .4078782 . . 1.0807877    .247941        0  .10162693 1.631337
       0          0         0 0 0         0   .401124   .10396002  .0985591 . . 1.1693814 .025326524        0  .10314787        .
      .5  .02390977        .5 2 2 .01662697 .17948684  .003808496 -.1843253 . . 1.9315214  .11211377        0          .  .690114
      .5 .014010232        .5 2 0 -.3077015  .5669612   .10396002  .0985591 . . .03633193  -.3270054        0 .011902187 .3908798
       0          . .26832914 2 0 -.4882525  .4053705 .0039266297  .5676779 . .  .3653373 .074105754 .5815899  .29764232 .3269372
      end
      
      set obs 1000
      set seed 5
      foreach var of varlist *{
          replace `var'= runiform()
      }
      replace firstmover_related_years= runiformint(1, 4)
      replace related_serv_entry_years= runiformint(1, 3)
      gen id= runiformint(1, 50)
      bys id: gen year=_n
      
      local xvars "i.firstmover_related c.related_share_w#c.related_speed_w#c.related_invest_firm_w c.rslack2_w c.advint_w c.mgrowth_w c.mdynamism1_w c.mmunificence_w c.related_share_w##c.related_share_w##c.related_invest_firm_w c.related_share_w##c.related_share_w##c.serv_share_w c.related_share_w##c.related_share_w##i.firstmover_related_years c.related_share_w##c.related_share_w##i.related_serv_entry_years c.related_share_w##c.related_share_w##c.related_speed_w"
      
      xtset id year
      xtreg tobinq3_ln `xvars' , fe vce (robust)
      
      summarize related_share_w
              local MyMin = max((r(mean) - r(sd)),r(min))
              local MyMax = min((r(mean) + r(sd)),r(max))
              local Grid = (`MyMax'-`MyMin')/10
          
      summarize related_invest_firm_w
              local MyMin4 = max((r(mean) - r(sd)),r(min))
              local MyMax4 = min((r(mean) + r(sd)),r(max))
              local Grid4 = (`MyMax4'-`MyMin4')/2
              local riv (`MyMin4' `Grid4' `MyMax4')
              
              summarize related_speed_w
              local MyMin5 = max((r(mean) - r(sd)),r(min))
              local MyMax5 = min((r(mean) + r(sd)),r(max))  
              local Grid5 = (`MyMax5'-`MyMin5')/2
      
      set scheme s1color    
      marginscontplot2 related_share_w related_speed_w, var1(10) var2(3) ///
      at(related_invest_firm_w = `MyMin4') areaopts(bla (format(%5.2f)) ///
      yla("TobinQ", format(%5.2f)) xla("Service relatedness", format(%5.2f))) ///
      lineopts(legend(label(1 "slow related serv speed") ///
      label(2 "medium related serv speed") label(3 "fast related serv speed")))
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	45.3 KB
ID:	1650907

      Comment


      • #4
        Thank you for your answer, Andrew Musau!
        The hint with the legend worked. Do you know how to fix the axis names? I have tried both "yla" and "ytitle" options (that worked before e.g. with ci option) but they seem not to be allowed in the combination with legend manipulation...

        Re. the issues in question 1:
        The plot appears every time empty like in the example shown in my second post. I have deleted all "capture" notations from the code as you have suggested, but there are no error messages appearing - the code runs smoothly producing those empty graphs... Any other ideas from where the issue could be coming from? I have tried now to replicate the code outside the loop - it works. Within - not anymore.

        Would appreciate any ideas on what to be changed.
        Last edited by Kseniya Levykina; 20 Feb 2022, 08:00.

        Comment


        • #5
          Originally posted by Kseniya Levykina View Post
          The hint with the legend worked. Do you know how to fix the axis names? I have tried both "yla" and "ytitle" options (that worked before e.g. with ci option) but they seem not to be allowed in the combination with legend manipulation...
          .
          You can put all these options within -plotopts()- and do away with -lineopts()-

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float(related_share_w related_invest_firm_w serv_share_w) byte(related_serv_entry_years firstmover_related_years) float(related_speed_w rslack2_w advint_w mgrowth_w mdynamism1_w mmunificence_w emp_ln roa_w total_divers_w mint_w tobinq3_ln)
          .5 .030393185        .5 2 0  .3228407 .50553256   .09835758  .4078782 . . 1.0807877    .247941        0  .10162693 1.631337
           0          0         0 0 0         0   .401124   .10396002  .0985591 . . 1.1693814 .025326524        0  .10314787        .
          .5  .02390977        .5 2 2 .01662697 .17948684  .003808496 -.1843253 . . 1.9315214  .11211377        0          .  .690114
          .5 .014010232        .5 2 0 -.3077015  .5669612   .10396002  .0985591 . . .03633193  -.3270054        0 .011902187 .3908798
           0          . .26832914 2 0 -.4882525  .4053705 .0039266297  .5676779 . .  .3653373 .074105754 .5815899  .29764232 .3269372
          end
          
          set obs 1000
          set seed 5
          foreach var of varlist *{
              replace `var'= runiform()
          }
          replace firstmover_related_years= runiformint(1, 4)
          replace related_serv_entry_years= runiformint(1, 3)
          gen id= runiformint(1, 50)
          bys id: gen year=_n
          
          local xvars "i.firstmover_related c.related_share_w#c.related_speed_w#c.related_invest_firm_w c.rslack2_w c.advint_w c.mgrowth_w c.mdynamism1_w c.mmunificence_w c.related_share_w##c.related_share_w##c.related_invest_firm_w c.related_share_w##c.related_share_w##c.serv_share_w c.related_share_w##c.related_share_w##i.firstmover_related_years c.related_share_w##c.related_share_w##i.related_serv_entry_years c.related_share_w##c.related_share_w##c.related_speed_w"
          
          xtset id year
          xtreg tobinq3_ln `xvars' , fe vce (robust)
          
          summarize related_share_w
                  local MyMin = max((r(mean) - r(sd)),r(min))
                  local MyMax = min((r(mean) + r(sd)),r(max))
                  local Grid = (`MyMax'-`MyMin')/10
              
          summarize related_invest_firm_w
                  local MyMin4 = max((r(mean) - r(sd)),r(min))
                  local MyMax4 = min((r(mean) + r(sd)),r(max))
                  local Grid4 = (`MyMax4'-`MyMin4')/2
                  local riv (`MyMin4' `Grid4' `MyMax4')
                  
                  summarize related_speed_w
                  local MyMin5 = max((r(mean) - r(sd)),r(min))
                  local MyMax5 = min((r(mean) + r(sd)),r(max))  
                  local Grid5 = (`MyMax5'-`MyMin5')/2
          
          set scheme s1color    
          marginscontplot2 related_share_w related_speed_w, var1(10) var2(3) ///
          at(related_invest_firm_w = `MyMin4')  ///
          plotopts(ytitle("TobinQ") xtitle("Service relatedness") legend(label(1 "slow related serv speed") ///
          label(2 "medium related serv speed") label(3 "fast related serv speed")))
          Res.:
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	44.3 KB
ID:	1651053



          Re. the issues in question 1:
          The plot appears every time empty like in the example shown in my second post. I have deleted all "capture" notations from the code as you have suggested, but there are no error messages appearing - the code runs smoothly producing those empty graphs... Any other ideas from where the issue could be coming from? I have tried now to replicate the code outside the loop - it works. Within - not anymore.
          The reason why I did not answer in #3 is because I cannot replicate the issue with the data example that you provided. I suggest that you use dataex to provide sufficient data to run the regressions and codes up to until when the empty graphs are created. I suspect it has something to do with empty locals, but without a data example, I cannot be sure.

          Comment


          • #6
            Originally posted by Andrew Musau View Post
            You can put all these options within -plotopts()- and do away with -lineopts()-
            This worked, thank you!


            Originally posted by Andrew Musau View Post
            The reason why I did not answer in #3 is because I cannot replicate the issue with the data example that you provided. I suggest that you use dataex to provide sufficient data to run the regressions and codes up to until when the empty graphs are created. I suspect it has something to do with empty locals, but without a data example, I cannot be sure.
            Would appreciate your help here!
            Below is the dataset example. It just misses two 0/1 dummy variables (i.firstmover_related_sic4 and i.related_serv_entry) as well as total_divers_w (category variable) as I needed to cut down the amount of variables for the dataex to work They are irrelevant for the issue I am experiencing though as they are not part of moderating effects.

            I am not sure how (and if connected to the issue or not) but I had already 3 times this week a situation that my main IV (related_serv_share_w) was out of the blue starting to be ommited - and for a good reason - because all its values were the same... It happens out of the blue and I have cross-checked my code multiple times and do not see what could be causing this... The IV itself is obviously not always the same.

            sum related_share_w

            Variable | Obs Mean Std. dev. Min Max
            -------------+---------------------------------------------------------
            related_sh~w | 15,749 .3146909 .2404343 0 1


            Btw, the code for creating plots outside the loop for a specific model works well, so cannot be the issue with the model specification itself.

            Could my laptop CPU just not managing it?.. or Stata does not allow for such a combination of loops and local variables?.. The output does not reflect any visible issues, MEs are not ommited and in most cases significant.

            Would be super thankful if you could help me solve this mystery.

            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input float(tobinq3_ln emp_ln roa_w mint_w related_invest_firm_w serv_share_w related_share_w) byte(firstmover_related_years related_serv_entry_years) float(related_speed_w rslack2_w advint_w mgrowth_w mdynamism1_w mmunificence_w) int fyear long gvkey
               .7848509   4.823502    .09379926  .1578708            0          0         0 0 0             .   .017402716  .0003146874  .0985601        .         . 2000   4321
               .7609209    .860778     .0422809 .19958515            .  .07295348         0 0 1             .    .28960717    .05299297  .1269929        .         . 2000  31881
              .31038535  2.0714095    .05805262  .1999217   .004732242  .29136798 .29136798 0 6             .            .   .033747077 -.0113661        .         . 2000   4608
              -.3143367   2.587764    .07777368 .10615554   .007890685   .2478666 .08544303 0 6             .    .00681902  .0032615084  .4534543        .         . 2000  10156
              -.1787295  3.1135154    .06135572  .2901172   .002765341  .03940076 .03940076 0 6             .     .1012987   .010422062  .1563901        .         . 2000  66290
              1.0881475   4.193783    .04792012  .0455299    .04470805   .5082228 .43920425 0 6             .    .52155054  .0001237717  .5676779        .         . 2000  17110
              1.0044551  .11243543   -2.1908383 1.4390665            .         .5        .5 0 6             . -.0039757993    .02986847  .0563062        .         . 2000  28780
              .13881889   .5877867   -.52961814         .            0          0         0 0 0             0    .04981308   .020921124 -.0401082 .1534871  .2170635 2001  27980
               .1720782   3.402097   -.04864997         .            .         .5  .4052071 0 6     .06125764    .10974248    .14640127 -.2468091 .0892523  .1262218 2001 100572
               .8378624   .4094571    -.0796583         .            0         .5         0 0 0             0     .9180082   .032017026   .212974 .0812928  .1149653 2001  66698
              -.4533352 .062974796   -.07978018 .53837407    .00495605  .16845638 .16845638 0 6     .03517898     .6151222    .00518431  .1194682 .0196564 -.0220342 2001   7662
              1.6934712 .002995509   -1.1072985         .            0          1         0 0 0             0     .5909586   .032017026   .212974 .0812928  .1149653 2001   4632
              .26197195   .1552929    -.4579985 .24166413    .00865023         .5        .5 0 1      .4745248      .487733    .06488617  .1473324 .1581407   .155443 2002 142106
               2.426792  .03922071    -1.229139         .            0         .5        .5 0 6      .6589744     .4842715    .06488617  .1473324 .1581407   .155443 2002  62525
                .325812  4.1108737   .072125666 .20636496    .00962454   .3042976  .3042976 0 6   .0034827804    .06780979   .012876568  .0262967 .0459932  .0459141 2002   1567
                      .   .9555115   -.00988836   .118039   .006598862         .5        .5 0 6       .083041    .22798176            .  .0785978 .0196564  .0031292 2003  24363
              .29319474  1.7346598  -.009238891         .            0  .20308124         0 0 0             0      .183458   .015126022  .2035465 .0275992  .0128625 2003  28169
               .2240478  4.1257625   .033247266         .   .014566396         .5        .5 0 6     .07377672     .0574319   .034406867  .0451583 .0659868  .0350492 2003   1932
                      .  .19885086    .08413599         .   .008377804   .3470919  .3470919 0 3     .04711365    .15240052            . -.0064108  .106508  .0622299 2003 157195
              1.0375041  .01587335    -.3793494         .            0         .5         0 0 0             0     .8637044    .05364179  .1948094 .1983459  .1525086 2003  63650
               .9829553   3.962811     .1501672  .1525084  .0011330891  .10132405 .09539976 0 6    .003538677     .4934365   .005145611   .053039  .100377 -.0153722 2003  23671
              1.8096327          .    .32852405         .    .03738048         .5        .5 0 2     .26723018      .643171    .06834359  .0526346 .1006112   .061804 2004 150049
              2.3382528   .0861777   -1.2275952         .            0          0         0 0 0             0       .65146    .04632083  .3191205 .2506773  .1570704 2004  61140
               2.112718   .1889661   .004911655  .5790566   .012306242         .5        .5 0 6     .13010591    .55477387    .03570768  .1145556  .110137  .0642586 2004 113646
               .7686204   1.373209    .01939308 .04967603   .013102957         .5        .5 0 6       .452404    .13013332   .002779435  .1487724 .1515474  .0059926 2004 121718
              .02582368   4.394449 -.0010228833 .05660929            .  .25181395 .13897674 0 6     .02521943    .12996463 .00003758286  .0422874 .0569512 -.0023144 2004   6104
               .7983317   .3611648    -.3395116         .   .008134819         .5        .5 0 6     .05817076     .6209395    .04632083  .3191205 .2506773  .1570704 2004  24191
               .3162146  2.1459312    .04471182         .            0  .19274406         0 0 6             0    .27595577            .  .1715492 .0946458  .0458606 2004  63892
             -.08603232    1.94591   -.05786978         .            0          0         0 0 0             0     .3946433 .00026442113  .1369476  .221637  .0957076 2004  12945
               .4606872  2.2192035    .07211726 .16775244            .  .19269586         0 0 6             0     .3689902     .0053029 -.3212994 .4380006 -.2459898 2005   1013
               .2354246  1.5777408    .04488036 .08473903            .  .12126755 .12126755 0 6 -.00056963135     .3619312   .064995244  .0606198 .0800927   .048892 2005  27845
              1.1164353  .05921186   -.12588169         .            0          1         0 0 0             0     .9180082    .06450459  .0477781 .3152253  .1960053 2006 175490
              1.2329425  .13976195    -.8753324  .5143153    .02008357         .5        .5 0 5    -.04508418   -.09753435    .05505301  .1075633 .0764989  .0466995 2006  21776
               .5606723  .11511281  .0004680721 .04810813            0          0         0 0 0             0   -.03896297 .00026916884  .1301644 .2290267   .135468 2006  22447
             -.08027358   .4916428    .04601306  .1703362            0          0         0 0 0             0    .54168564   .035665322   .089169 .2120358  .1317077 2007 124599
               -.399642   2.664098    .05205785 .06762296   .031365436         .5        .5 0 6     .05881027    .28621104    .01934083 -.0556188 .1127145  .0710673 2007   3502
               .6249356   .3184537     .1056816 .12252179   .006941673         .5        .5 0 6     .04062482      .629997   .009907473 -.0094299 .5751907  .3202132 2008   1554
               .0791311   .3257001    -.7519036   .394089            .          0         0 0 0             0     .4397037    .05035086   .400203 .6166023  .2904669 2008 176289
              .30570945   3.671403   .019298565 .03370411   .013241073         .5        .5 0 5     .08912627     .0895028    .04594743  .1061201 .1238433  .0770902 2008  14538
               -.404595   .4567917   .030791067 .25864494            0          0         0 0 0             0    .53367144   .002500745  .1213146  .242247  .1495817 2008 154039
               .7171892  .09893995   -1.4863456         .   .001268631         .5        .5 0 2     -.3072607   -.14582048    .04594743  .1061201 .1238433  .0770902 2008 137090
              .12294675  1.4546537    .02186161 .08291958            0          0         0 0 0             0    .16752715    .02660585  .0409528 .1452685  .0892615 2008 140073
              .43284905   .3364722    -.1905255   .352308            .          0         0 0 5             0     .0771689   .012657824 -.0902959 .2052577  .1282007 2009   2615
              1.0158616  .09893995    .04893112   .421061   .033051565         .5        .5 0 5     .12597282    .23657957   .011553893 -.1800803 .0793911 -.0095313 2009 140568
              -.4013298   .9246557    -.5914695  .2264245            . .010736873         0 0 5             0     .4026991   .012657824 -.0902959 .2052577  .1282007 2009 176572
              1.2657076  .06672363   -.09701755 .14858375     .0233438   .3125573  .3125573 0 6     .06101055     .7263314   .004812488 -.0554356 .2706033  .1599108 2009  22772
              1.2786903   .8078142   -.05703359  .1443821   .005066807         .5        .5 0 6    -.28294092     .6169168  .0013525464 -.3540866 .1422588  .0642505 2009 119217
               .3343047   2.995732  -.013862024 .25660864    .01220553         .5        .5 0 3    .018552037   -.11718246   .033179287  .1027484 .1478671  .0769442 2010 186106
               .6748155  .16296883    .12127334  .1585988            0          0         0 0 0             0    .14379022  .0006651215  .0711325 .1507824  .0699476 2010   7275
              1.5621953  .22074066   -.06504746         .   .002883954         .5        .5 0 2     4.6426644     .6983135    .07158631  .3801093  .164608  .1024965 2010  29127
               2.285278  .01093994   -1.5156608 1.4759357            0         .5         0 0 0             0     .3621085    .07158631  .3801093  .164608  .1024965 2010  17199
               .2641863   3.068053   .009631724         .            0          0         0 0 0             0      .312941  .0043012206  .3483179  .289465  .0859566 2010   8030
               .9586152  .09803374   -.09194283         .   .003342111         .5        .5 0 5      .3095205       .19905     .0891718 -.0192611 .2746698  .1628105 2011  63789
              2.2531905   .0295588    -2.479596  .7215673  .0009709247         .5        .5 0 5     -.1510345    -.7912245     .0891718 -.0192611 .2746698  .1628105 2011 150681
              .10896432   .4014571    .06012107  .3549808   .019987734         .5        .5 0 5     .02609558     .5656372    .10686467 -.2647169 .2238971   .040329 2011 148410
              1.1281307   .4706284    .05120875  .2220402            .    .153413         0 0 0             0     .4844665    .00896014  .0879143 .1415469 -.0744587 2011 133504
              1.2348735  .08801088    -.5167021         .  .0041057286         .5        .5 0 2     -.4886095      .873804    .04535521  .0512946 .0782316  .0306431 2011  66374
              .18889026  3.0175915   .002986996 .09882838            .          0         0 0 5             0     .2194412    .02698818  .0400514 .1081721   .036182 2011 134932
               1.253284   3.505557    .11170086  .8943401            .          0         0 0 0             0     .2778495    .22540323  .0884996 .0595145  .0338459 2011  61567
               .1760963  1.1675162    -.5078523  .4390673            .         .5  .4226401 0 5    -.04334405     .2779963   .022243604 -.1050541 .0795161  .0200203 2012  65676
              -.1543786  4.7095304    .04011765 .10807122            0          0         0 0 5             0   .009923422     .0501752 -.3458401  .159199  .0943552 2012 142953
              -.2010345   5.147494   .029729106  .0222719            0  .05724309         0 0 6             0            .   .033034533  .0857837 .0975051  .0030625 2012   4839
             -1.0526038  .27002713   -.02918419 1.5947195   .003252102         .5        .5 0 5    -.06787116     .2329899    .05770202 -.0066467 .0674108  .0243166 2012 112968
              -.5599229          .    .07117602         .  .0003622083         .5        .5 0 6    -.11512945     .8602226  .0010557362 -.0820707 .0951122 -.0096444 2012   4322
              1.2375153  .11689375    .16002455         .   .006108569         .5        .5 0 5      .3807782     .6565454    .02408848   .051797  .132722  .0676587 2013  25274
                      .   .6178847     .1074961 .14491795            .  .56771827 .56771827 0 6     .13135852     .3992852  .0023379384  .0093312 .0832263 -.0491092 2013 120334
               1.229882  .22633845    -.6804233         .   .033082955         .5        .5 0 4   -.011600357     .5660103     .1304342  .1081781 .2152189  .1281656 2013 187631
              .08078062   .2390169    .09638269 1.5947195            0          0         0 0 5    -.49030855      .242663    .05855259 -.0384414 .0649264  .0340165 2014 112968
                .495358   3.505557    .06420399         .    .01345569         .5 .19027944 0 5   .0018950186      .141989   .014810282  .0647262 .1272278     .0699 2014  25119
              2.1051013 .023716526    -.6430309         .            0          0         0 0 6             0     .9180082    .05855259 -.0384414 .0649264  .0340165 2014  61711
               .1548965    4.74054    .04507557  .0930364   .005585724   .4103316  .4103316 0 5    -.04446429    .10673362    .05855259 -.0384414 .0649264  .0340165 2014 101204
              .19248314  .26390153   -.11090314 .08423702            .         .5  .3123127 0 4    -.04438356    .55569917    .11733554  .3268772 .1769858  .1044959 2014 287111
               .8350369   1.954445     .1052158 .06871224    .00638334         .5        .5 0 5    .015236304     .6664457  .0003254873  .0200838 .2775941  .1436236 2014   6304
                      .          .    .22834314  .4695122   .014080765         .5        .5 0 1     2.0844495     .6103869    .11849286  .1464773  .215206  .1207214 2015  29819
               .6144309   .1638181     .0842822         .   .001372668          1         1 0 6   -.022745896   -.07335822    .21310432 -.3540866 .5346682   -.25036 2015  11099
               1.273602    .486123    .08623577 .14147058    .01250982         .5        .5 0 6    .063089214     .4657506    .02103505    .04476 .0503215  .0239095 2016  66032
                      .  .03246719   -.40795135         .  .0014515645         .5        .5 0 2      .4728868     .9002963    .18845367  .0242622   .26892  .1650526 2016  20649
              1.0533974   .3457151    .08022884         .   .009095096         .5        .5 0 4     .08781967    .17323916    .23802033  .1117782 .0537244 -.0287804 2017  27907
             -.20849203   3.493138   -.01172919         .  .0043519395         .5        .5 0 6     .11343263     .2406711   .000770015  .0736843 .4008673 -.2107781 2017  63892
               .6327091   .7929925    .09521452  .0884436   .003015482         .5        .5 0 5     .04392552    .13161069    .05901711  .0601625 .0323105 -.0165146 2017 177287
              .57378364  .02176149    -.9840254  .5287629            .         .5        .5 0 2     .13006924     .8197925    .05901711  .0601625 .0323105 -.0165146 2017  22673
              1.1433774   .0889262     -.330507         .   .030886976         .5        .5 0 5     4.6426644     .4729961    .16464807  .0801713 .2368033  .1452577 2017  28806
              .57351905   2.564949     .0559416 .11542431    .00857902   .3647216 .21440004 0 2     .05255561    .11368404   .003823045 -.0833807 .0602712 -.0162126 2017  25313
              1.0847316   1.974081    .04033872 .21344623    .01064477   .4461439  .4461439 0 6    .028331175     .4281755  .0035601575  .1397957 .0559189  .0133162 2017 138483
              1.0608491  .15186235    -.3120433  .5399464  .0006356341         .5        .5 5 5    -.05118175     .4100504    .05794144   .024669  .036263   .002114 2018 148219
             -.12918393  .08250123    -.4979927         .  .0009847818         .5        .5 0 1    .031035716     .8653318    .21077794  -.079611 .1877912  .1126617 2018  20645
              .10115924  2.1972246   -.03804166  .1269821            .          1  .9079978 0 5      .8224569    .09330612            .  .5676779 .0305489  .0148224 2018  29133
              -.3988963   3.508556    .02427054 .16404465            0          0         0 0 6             0    .09708216    .02100626 -.0148728 .0967157 -.0476901 2018  11636
              .14672288  .08434115   -.07860715  .2482428    .01452301         .5        .5 0 5    -.04761712     .6542991   .017990572  .0658518 .0749658  .0381734 2018 187722
               -.479711   .5329784     .0118223  .3726555   .021507313         .5        .5 0 5    .001306473    .23707396   .001748318  .1107581 .0950972  .0539121 2018 176572
              1.0450197 .030529205    -.6992819         .   .012784198         .5        .5 0 2      1.102907     .7291766    .21077794  -.079611 .1877912  .1126617 2018  33855
               .8040774   3.134015    .08337508 .19282512            .  .49374425  .4788003 0 6  -.0043283016    .24309877    .05794144   .024669  .036263   .002114 2018 223098
               2.237253   .1088544   .011362627  .6865512     .0760708         .5        .5 0 5     .11931226  -.009143365    .21077794  -.079611 .1877912  .1126617 2018  14983
             -.50515175 .014888613    .02690395 .07336425    .03252682         .5        .5 0 5    -.11558288     .8904285   .017990572  .0658518 .0749658  .0381734 2018 178865
               .7284149  .09257919    -.9869902  .6672074  .0012297395         .5        .5 0 4    -.07799353    .06259931  .0019616564  .0646406 .0868421  .0382641 2019  33749
              .19357163   1.238664  -.036662143  .1194921            .  .11141197  .1112384 0 5   .0046351156     .4124315   .011774538 -.0272542 .0965563  .0529558 2019 233491
              .17441976   1.582272   .027865155 .22977446   .011411444         .5 .38164625 0 2    -.03740313     .4166619 .00023134355  -.316366 .1336143  .0321889 2019  12262
            -.064006954  .06578775    -.4593287  .7260736 .00007053181         .5        .5 0 4    -.06356863     -.355904   .009996342 -.0155631 .0365736  .0072712 2019  24421
               .7255015  .59332687   -.06502027  .4289426   .009199749         .5        .5 0 5    -.04219005     .4501246   .006215787   .053428 .0221087 -.0100668 2019  19849
              -.5828239   1.268355  -.006991435         .    .01452642   .4038349 .29716957 0 6  -.0002079461    .23394835   .013395392  .0033692 .0196564  .0010095 2019   2080
            end
            Last edited by Kseniya Levykina; 20 Feb 2022, 18:38.

            Comment


            • #7
              I suspect those 2 issues are actually connected and lead to missing local variables. When related_share_w appears out of the blue to be of the same value for all observations it is becoming its mean... Have just experienced it again.

              Looks like something in this part of the code goes wrong within a loop...
              Code:
              summarize related_share_w        
              local MyMin = max((r(mean) - r(sd)),r(min))        
              local MyMax = min((r(mean) + r(sd)),r(max))        
              local Grid = (`MyMax'-`MyMin')/10
              Does anyone have ideas on how this part of code could be improved to avoid this issue?

              Comment


              • #8
                You need to exit the loop and go back to your regressions to see whether they are correctly specified. From the data example which may not be representative of your full dataset, the graph turns up empty because your main variable specified in the margins command was omitted from the regression and therefore Stata cannot compute the marginal effects. You mask this by using the capture commands.

                Code:
                * Example generated by -dataex-. For more info, type help dataex
                clear
                input float(tobinq3_ln emp_ln roa_w mint_w related_invest_firm_w serv_share_w related_share_w) byte(firstmover_related_years related_serv_entry_years) float(related_speed_w rslack2_w advint_w mgrowth_w mdynamism1_w mmunificence_w) int fyear long gvkey
                   .4606872  2.2192035    .07211726 .16775244            .  .19269586         0 0 6             0     .3689902     .0053029 -.3212994 .4380006 -.2459898 2005   1013
                   .6249356   .3184537     .1056816 .12252179   .006941673         .5        .5 0 6     .04062482      .629997   .009907473 -.0094299 .5751907  .3202132 2008   1554
                    .325812  4.1108737   .072125666 .20636496    .00962454   .3042976  .3042976 0 6   .0034827804    .06780979   .012876568  .0262967 .0459932  .0459141 2002   1567
                   .2240478  4.1257625   .033247266         .   .014566396         .5        .5 0 6     .07377672     .0574319   .034406867  .0451583 .0659868  .0350492 2003   1932
                  -.5828239   1.268355  -.006991435         .    .01452642   .4038349 .29716957 0 6  -.0002079461    .23394835   .013395392  .0033692 .0196564  .0010095 2019   2080
                  .43284905   .3364722    -.1905255   .352308            .          0         0 0 5             0     .0771689   .012657824 -.0902959 .2052577  .1282007 2009   2615
                   -.399642   2.664098    .05205785 .06762296   .031365436         .5        .5 0 6     .05881027    .28621104    .01934083 -.0556188 .1127145  .0710673 2007   3502
                   .7848509   4.823502    .09379926  .1578708            0          0         0 0 0             .   .017402716  .0003146874  .0985601        .         . 2000   4321
                  -.5599229          .    .07117602         .  .0003622083         .5        .5 0 6    -.11512945     .8602226  .0010557362 -.0820707 .0951122 -.0096444 2012   4322
                  .31038535  2.0714095    .05805262  .1999217   .004732242  .29136798 .29136798 0 6             .            .   .033747077 -.0113661        .         . 2000   4608
                  1.6934712 .002995509   -1.1072985         .            0          1         0 0 0             0     .5909586   .032017026   .212974 .0812928  .1149653 2001   4632
                  -.2010345   5.147494   .029729106  .0222719            0  .05724309         0 0 6             0            .   .033034533  .0857837 .0975051  .0030625 2012   4839
                  .02582368   4.394449 -.0010228833 .05660929            .  .25181395 .13897674 0 6     .02521943    .12996463 .00003758286  .0422874 .0569512 -.0023144 2004   6104
                   .8350369   1.954445     .1052158 .06871224    .00638334         .5        .5 0 5    .015236304     .6664457  .0003254873  .0200838 .2775941  .1436236 2014   6304
                   .6748155  .16296883    .12127334  .1585988            0          0         0 0 0             0    .14379022  .0006651215  .0711325 .1507824  .0699476 2010   7275
                  -.4533352 .062974796   -.07978018 .53837407    .00495605  .16845638 .16845638 0 6     .03517898     .6151222    .00518431  .1194682 .0196564 -.0220342 2001   7662
                   .2641863   3.068053   .009631724         .            0          0         0 0 0             0      .312941  .0043012206  .3483179  .289465  .0859566 2010   8030
                  -.3143367   2.587764    .07777368 .10615554   .007890685   .2478666 .08544303 0 6             .    .00681902  .0032615084  .4534543        .         . 2000  10156
                   .6144309   .1638181     .0842822         .   .001372668          1         1 0 6   -.022745896   -.07335822    .21310432 -.3540866 .5346682   -.25036 2015  11099
                  -.3988963   3.508556    .02427054 .16404465            0          0         0 0 6             0    .09708216    .02100626 -.0148728 .0967157 -.0476901 2018  11636
                  .17441976   1.582272   .027865155 .22977446   .011411444         .5 .38164625 0 2    -.03740313     .4166619 .00023134355  -.316366 .1336143  .0321889 2019  12262
                 -.08603232    1.94591   -.05786978         .            0          0         0 0 0             0     .3946433 .00026442113  .1369476  .221637  .0957076 2004  12945
                  .30570945   3.671403   .019298565 .03370411   .013241073         .5        .5 0 5     .08912627     .0895028    .04594743  .1061201 .1238433  .0770902 2008  14538
                   2.237253   .1088544   .011362627  .6865512     .0760708         .5        .5 0 5     .11931226  -.009143365    .21077794  -.079611 .1877912  .1126617 2018  14983
                  1.0881475   4.193783    .04792012  .0455299    .04470805   .5082228 .43920425 0 6             .    .52155054  .0001237717  .5676779        .         . 2000  17110
                   2.285278  .01093994   -1.5156608 1.4759357            0         .5         0 0 0             0     .3621085    .07158631  .3801093  .164608  .1024965 2010  17199
                   .7255015  .59332687   -.06502027  .4289426   .009199749         .5        .5 0 5    -.04219005     .4501246   .006215787   .053428 .0221087 -.0100668 2019  19849
                 -.12918393  .08250123    -.4979927         .  .0009847818         .5        .5 0 1    .031035716     .8653318    .21077794  -.079611 .1877912  .1126617 2018  20645
                          .  .03246719   -.40795135         .  .0014515645         .5        .5 0 2      .4728868     .9002963    .18845367  .0242622   .26892  .1650526 2016  20649
                  1.2329425  .13976195    -.8753324  .5143153    .02008357         .5        .5 0 5    -.04508418   -.09753435    .05505301  .1075633 .0764989  .0466995 2006  21776
                   .5606723  .11511281  .0004680721 .04810813            0          0         0 0 0             0   -.03896297 .00026916884  .1301644 .2290267   .135468 2006  22447
                  .57378364  .02176149    -.9840254  .5287629            .         .5        .5 0 2     .13006924     .8197925    .05901711  .0601625 .0323105 -.0165146 2017  22673
                  1.2657076  .06672363   -.09701755 .14858375     .0233438   .3125573  .3125573 0 6     .06101055     .7263314   .004812488 -.0554356 .2706033  .1599108 2009  22772
                   .9829553   3.962811     .1501672  .1525084  .0011330891  .10132405 .09539976 0 6    .003538677     .4934365   .005145611   .053039  .100377 -.0153722 2003  23671
                   .7983317   .3611648    -.3395116         .   .008134819         .5        .5 0 6     .05817076     .6209395    .04632083  .3191205 .2506773  .1570704 2004  24191
                          .   .9555115   -.00988836   .118039   .006598862         .5        .5 0 6       .083041    .22798176            .  .0785978 .0196564  .0031292 2003  24363
                -.064006954  .06578775    -.4593287  .7260736 .00007053181         .5        .5 0 4    -.06356863     -.355904   .009996342 -.0155631 .0365736  .0072712 2019  24421
                    .495358   3.505557    .06420399         .    .01345569         .5 .19027944 0 5   .0018950186      .141989   .014810282  .0647262 .1272278     .0699 2014  25119
                  1.2375153  .11689375    .16002455         .   .006108569         .5        .5 0 5      .3807782     .6565454    .02408848   .051797  .132722  .0676587 2013  25274
                  .57351905   2.564949     .0559416 .11542431    .00857902   .3647216 .21440004 0 2     .05255561    .11368404   .003823045 -.0833807 .0602712 -.0162126 2017  25313
                   .2354246  1.5777408    .04488036 .08473903            .  .12126755 .12126755 0 6 -.00056963135     .3619312   .064995244  .0606198 .0800927   .048892 2005  27845
                  1.0533974   .3457151    .08022884         .   .009095096         .5        .5 0 4     .08781967    .17323916    .23802033  .1117782 .0537244 -.0287804 2017  27907
                  .13881889   .5877867   -.52961814         .            0          0         0 0 0             0    .04981308   .020921124 -.0401082 .1534871  .2170635 2001  27980
                  .29319474  1.7346598  -.009238891         .            0  .20308124         0 0 0             0      .183458   .015126022  .2035465 .0275992  .0128625 2003  28169
                  1.0044551  .11243543   -2.1908383 1.4390665            .         .5        .5 0 6             . -.0039757993    .02986847  .0563062        .         . 2000  28780
                  1.1433774   .0889262     -.330507         .   .030886976         .5        .5 0 5     4.6426644     .4729961    .16464807  .0801713 .2368033  .1452577 2017  28806
                  1.5621953  .22074066   -.06504746         .   .002883954         .5        .5 0 2     4.6426644     .6983135    .07158631  .3801093  .164608  .1024965 2010  29127
                  .10115924  2.1972246   -.03804166  .1269821            .          1  .9079978 0 5      .8224569    .09330612            .  .5676779 .0305489  .0148224 2018  29133
                          .          .    .22834314  .4695122   .014080765         .5        .5 0 1     2.0844495     .6103869    .11849286  .1464773  .215206  .1207214 2015  29819
                   .7609209    .860778     .0422809 .19958515            .  .07295348         0 0 1             .    .28960717    .05299297  .1269929        .         . 2000  31881
                   .7284149   .0925792    -.9869902  .6672074  .0012297395         .5        .5 0 4    -.07799353    .06259931  .0019616564  .0646406 .0868421  .0382641 2019  33749
                  1.0450197 .030529205    -.6992819         .   .012784198         .5        .5 0 2      1.102907     .7291766    .21077794  -.079611 .1877912  .1126617 2018  33855
                  2.3382528   .0861777   -1.2275952         .            0          0         0 0 0             0       .65146    .04632083  .3191205 .2506773  .1570704 2004  61140
                   1.253284   3.505557    .11170086  .8943401            .          0         0 0 0             0     .2778495    .22540323  .0884996 .0595145  .0338459 2011  61567
                  2.1051013 .023716526    -.6430309         .            0          0         0 0 6             0     .9180082    .05855259 -.0384414 .0649264  .0340165 2014  61711
                   2.426792  .03922071    -1.229139         .            0         .5        .5 0 6      .6589744     .4842715    .06488617  .1473324 .1581407   .155443 2002  62525
                  1.0375041  .01587335    -.3793494         .            0         .5         0 0 0             0     .8637044    .05364179  .1948094 .1983459  .1525086 2003  63650
                   .9586152  .09803374   -.09194283         .   .003342111         .5        .5 0 5      .3095205       .19905     .0891718 -.0192611 .2746698  .1628105 2011  63789
                   .3162146  2.1459312    .04471182         .            0  .19274406         0 0 6             0    .27595577            .  .1715492 .0946458  .0458606 2004  63892
                 -.20849203   3.493138   -.01172919         .  .0043519395         .5        .5 0 6     .11343263     .2406711   .000770015  .0736843 .4008673 -.2107781 2017  63892
                   .1760963  1.1675162    -.5078523  .4390673            .         .5  .4226401 0 5    -.04334405     .2779963   .022243604 -.1050541 .0795161  .0200203 2012  65676
                   1.273602    .486123    .08623577 .14147058    .01250982         .5        .5 0 6    .063089214     .4657506    .02103505    .04476 .0503215  .0239095 2016  66032
                  -.1787295  3.1135154    .06135572  .2901172   .002765341  .03940076 .03940076 0 6             .     .1012987   .010422062  .1563901        .         . 2000  66290
                  1.2348735  .08801088    -.5167021         .  .0041057286         .5        .5 0 2     -.4886095      .873804    .04535521  .0512946 .0782316  .0306431 2011  66374
                   .8378624   .4094571    -.0796583         .            0         .5         0 0 0             0     .9180082   .032017026   .212974 .0812928  .1149653 2001  66698
                   .1720782   3.402097   -.04864997         .            .         .5  .4052071 0 6     .06125764    .10974248    .14640127 -.2468091 .0892523  .1262218 2001 100572
                   .1548965    4.74054    .04507557  .0930364   .005585724   .4103316  .4103316 0 5    -.04446429    .10673362    .05855259 -.0384414 .0649264  .0340165 2014 101204
                 -1.0526038  .27002713   -.02918419 1.5947195   .003252102         .5        .5 0 5    -.06787116     .2329899    .05770202 -.0066467 .0674108  .0243166 2012 112968
                  .08078062   .2390169     .0963827 1.5947195            0          0         0 0 5    -.49030855      .242663    .05855259 -.0384414 .0649264  .0340165 2014 112968
                   2.112718   .1889661   .004911655  .5790566   .012306242         .5        .5 0 6     .13010591    .55477387    .03570768  .1145556  .110137  .0642586 2004 113646
                  1.2786903   .8078142   -.05703359  .1443821   .005066807         .5        .5 0 6    -.28294092     .6169168  .0013525464 -.3540866 .1422588  .0642505 2009 119217
                          .   .6178847     .1074961 .14491795            .  .56771827 .56771827 0 6     .13135852     .3992852  .0023379384  .0093312 .0832263 -.0491092 2013 120334
                   .7686204   1.373209    .01939308 .04967603   .013102957         .5        .5 0 6       .452404    .13013332   .002779435  .1487724 .1515474  .0059926 2004 121718
                 -.08027358   .4916428    .04601306  .1703362            0          0         0 0 0             0    .54168564   .035665322   .089169 .2120358  .1317077 2007 124599
                  1.1281307   .4706284    .05120875  .2220402            .    .153413         0 0 0             0     .4844665    .00896014  .0879143 .1415469 -.0744587 2011 133504
                  .18889026  3.0175915   .002986996 .09882838            .          0         0 0 5             0     .2194412    .02698818  .0400514 .1081721   .036182 2011 134932
                   .7171892  .09893995   -1.4863456         .   .001268631         .5        .5 0 2     -.3072607   -.14582048    .04594743  .1061201 .1238433  .0770902 2008 137090
                  1.0847316   1.974081    .04033872 .21344623    .01064477   .4461439  .4461439 0 6    .028331175     .4281755  .0035601575  .1397957 .0559189  .0133162 2017 138483
                  .12294675  1.4546537    .02186161 .08291958            0          0         0 0 0             0    .16752715    .02660585  .0409528 .1452685  .0892615 2008 140073
                  1.0158616  .09893995    .04893112   .421061   .033051565         .5        .5 0 5     .12597282    .23657957   .011553893 -.1800803 .0793911 -.0095313 2009 140568
                  .26197195   .1552929    -.4579985 .24166413    .00865023         .5        .5 0 1      .4745248      .487733    .06488617  .1473324 .1581407   .155443 2002 142106
                  -.1543786  4.7095304    .04011765 .10807122            0          0         0 0 5             0   .009923422     .0501752 -.3458401  .159199  .0943552 2012 142953
                  1.0608491  .15186235    -.3120433  .5399464  .0006356341         .5        .5 5 5    -.05118175     .4100504    .05794144   .024669  .036263   .002114 2018 148219
                  .10896432   .4014571    .06012107  .3549808   .019987734         .5        .5 0 5     .02609558     .5656372    .10686467 -.2647169 .2238971   .040329 2011 148410
                  1.8096327          .    .32852405         .    .03738048         .5        .5 0 2     .26723018      .643171    .06834359  .0526346 .1006112   .061804 2004 150049
                  2.2531905   .0295588    -2.479596  .7215673  .0009709247         .5        .5 0 5     -.1510345    -.7912245     .0891718 -.0192611 .2746698  .1628105 2011 150681
                   -.404595   .4567917   .030791067 .25864494            0          0         0 0 0             0    .53367144   .002500745  .1213146  .242247  .1495817 2008 154039
                          .  .19885086    .08413599         .   .008377804   .3470919  .3470919 0 3     .04711365    .15240052            . -.0064108  .106508  .0622299 2003 157195
                  1.1164353  .05921186   -.12588169         .            0          1         0 0 0             0     .9180082    .06450459  .0477781 .3152253  .1960053 2006 175490
                   .0791311   .3257001    -.7519036   .394089            .          0         0 0 0             0     .4397037    .05035086   .400203 .6166023  .2904669 2008 176289
                  -.4013298   .9246557    -.5914695  .2264245            . .010736873         0 0 5             0     .4026991   .012657824 -.0902959 .2052577  .1282007 2009 176572
                   -.479711   .5329784     .0118223  .3726555   .021507313         .5        .5 0 5    .001306473    .23707396   .001748318  .1107581 .0950972  .0539121 2018 176572
                   .6327091   .7929925    .09521452  .0884436   .003015482         .5        .5 0 5     .04392552    .13161069    .05901711  .0601625 .0323105 -.0165146 2017 177287
                 -.50515175 .014888613    .02690395 .07336425    .03252682         .5        .5 0 5    -.11558288     .8904285   .017990572  .0658518 .0749658  .0381734 2018 178865
                   .3343047   2.995732  -.013862024 .25660864    .01220553         .5        .5 0 3    .018552037   -.11718246   .033179287  .1027484 .1478671  .0769442 2010 186106
                   1.229882  .22633845    -.6804233         .   .033082955         .5        .5 0 4   -.011600357     .5660103     .1304342  .1081781 .2152189  .1281656 2013 187631
                  .14672288  .08434115   -.07860715  .2482428    .01452301         .5        .5 0 5    -.04761712     .6542991   .017990572  .0658518 .0749658  .0381734 2018 187722
                   .8040774   3.134015    .08337508 .19282512            .  .49374425  .4788003 0 6  -.0043283016    .24309877    .05794144   .024669  .036263   .002114 2018 223098
                  .19357163   1.238664  -.036662143  .1194921            .  .11141197  .1112384 0 5   .0046351156     .4124315   .011774538 -.0272542 .0965563  .0529558 2019 233491
                  .19248314  .26390153   -.11090314 .08423702            .         .5  .3123127 0 4    -.04438356    .55569917    .11733554  .3268772 .1769858  .1044959 2014 287111
                end
                
                xtset gvkey fyear
                
                local DVs "tobinq3_ln" // could be switched to several - to simplify for now just 1
                local controls "c.emp_ln c.roa_w"
                local EXTRAs "c.mint_w" // could be switched to several - to simplify for now just 1
                
                local Model3 "i.related_serv_entry c.related_share_w##c.related_share_w##c.related_invest_firm_w c.related_share_w##c.related_share_w##c.serv_share_w c.related_share_w##c.related_share_w##i.firstmover_related_years c.related_share_w##c.related_share_w##i.related_serv_entry_years c.related_share_w##c.related_share_w##c.related_speed_w c.related_share_w##c.related_share_w##c.rslack2_w c.related_share_w##c.related_share_w##c.advint_w c.related_share_w##c.related_share_w##c.mgrowth_w c.related_share_w##c.related_share_w##c.mdynamism1_w c.related_share_w##c.related_share_w##c.mmunificence_w"
                
                
                local cMEs "c.related_invest_firm_w c.serv_share_w c.related_speed_w c.rslack2_w c.advint_w c.mgrowth_w c.mdynamism1_w c.mmunificence_w"
                local iMEs "firstmover_related_years related_serv_entry_years"
                
                foreach DV of local DVs {
                    foreach EXTRA of local EXTRAs {
                    local Mymodel "FEr-yd-6"
                    forv i = 3/3 {
                 
                    xtreg `DV' `Model`i'' `controls' `EXTRA' i.fyear, fe vce (robust) // thats were the regression is defined
                  
                ***** Creating margin plots for the continious MEs (above point (b)), e.g. for c.related_share_w##c.related_share_w##c.related_invest_firm_w - this worked perfectly just 3 days ago and suddenly started to produce empty graphs instead (the axes, legend are there - just the graphs themselves are missing!)
                        summarize related_share_w
                        local MyMin = max((r(mean) - r(sd)),r(min))
                        di "My Min is `MyMin'"
                        local MyMax = min((r(mean) + r(sd)),r(max))
                        di "My Max is `MyMax'"
                        local Grid = (`MyMax'-`MyMin')/10
                        di "My Grid is `Grid'"
                    
                        foreach cME of local cMEs {
                        quietly summarize `cME'
                        local MyMin2 = max((r(mean) - r(sd)),r(min))
                        di "My Min 2 is `MyMin2'"
                        local MyMax2 = min((r(mean) + r(sd)),r(max))
                        di "My Max 2 is `MyMax2'"
                        local Grid2 = (`MyMax2'-`MyMin2')/2
                        di "My Grid2 is `Grid2'"
                        
                    margins, at(c.related_share_w=(`MyMin' (`Grid') `MyMax') `cME'=(`MyMin2' (`Grid2') `MyMax2'))
                                }
                            }
                    }
                }
                From the above, your variable "related_share" is collinear with some variables and it is dropped from the estimation. You can install reghdfe from SSC and absorb the panel and year indicators, and this will show you which variables are collinear with these indicators. In xtreg, the order of the variables matters and it may be harder to detect the collinearity.


                Code:
                local Model3 "i.related_serv_entry c.related_share_w##c.related_share_w##c.related_invest_firm_w c.related_share_w##c.related_share_w##c.serv_share_w c.related_share_w##c.related_share_w##i.firstmover_related_years c.related_share_w##c.related_share_w##i.related_serv_entry_years c.related_share_w##c.related_share_w##c.related_speed_w c.related_share_w##c.related_share_w##c.rslack2_w c.related_share_w##c.related_share_w##c.advint_w c.related_share_w##c.related_share_w##c.mgrowth_w c.related_share_w##c.related_share_w##c.mdynamism1_w c.related_share_w##c.related_share_w##c.mmunificence_w"
                xtreg tobinq3_ln c.emp_ln c.roa_w c.mint_w `Model3' i.fyear, fe robust
                reghdfe tobinq3_ln c.emp_ln c.roa_w c.mint_w `Model3', absorb(gvkey fyear) cluster(gvkey)

                Comment


                • #9
                  Originally posted by Andrew Musau View Post

                  From the above, your variable "related_share" is collinear with some variables and it is dropped from the estimation. You can install reghdfe from SSC and absorb the panel and year indicators, and this will show you which variables are collinear with these indicators. In xtreg, the order of the variables matters and it may be harder to detect the collinearity.
                  Thank you for your answer!!

                  The related_share_w is being ommited a few times in each model as I have several MEs that include it, but at least once pure "related_share_w" as well as squared one "related_share_w" are taken over and is estimated. In the loop it starts though sometimes to get ommited completely and so far I could see - when Stata hard-change the values of this variable (making it a constant) without me explicitly asking to do that (!) - or at least I do not recognise which of my codes could be causing Stata to do this... Outside the loop the models seem to work well.

                  I was not aware of variable sequence being able to influence the model results... that's definitely an issue I need to address and cross-check.

                  I have tried out the reghdfe suggestion (see example below). Could you please check if I am missing something? Related_share_w and some of the MEs are significant here, I do not see indications of which variable could be causing multicollinearity apart from maybe the categorical ones (??).

                  Could it be that the use of "##" instead of "#" in the model definition "c.related_share_w##c.related_share_w##" + ME several times could be causing an issue?.. Especially taking into account that variable sequence in the model definition matters.

                  Code:
                  . local DV "tobinq3_ln"
                  
                  . 
                  . local controls "c.emp_ln c.roa_w c.total_divers_w"
                  
                  . 
                  . local EXTRA "c.mint_w" // could be alco included: c.mint_w c.mcompetition_w c.mturbulence_w c.c_gdp_growth c.c_inf c.c_serv_growth c.c_serv_pw
                  
                  . 
                  . local Model3 "i.firstmover_related_sic4 i.related_serv_entry c.related_share_w##c.related_share_w##c.related_invest_firm_w c.related_share_w##c.related_share_w##c.serv_share_w c.related_share_
                  > w##c.related_share_w##i.firstmover_related_years c.related_share_w##c.related_share_w##i.related_serv_entry_years c.related_share_w##c.related_share_w##c.related_speed_w c.related_share_w##c.r
                  > elated_share_w##c.rslack2_w c.related_share_w##c.related_share_w##c.advint_w c.related_share_w##c.related_share_w##c.mgrowth_w c.related_share_w##c.related_share_w##c.mdynamism1_w c.related_sh
                  > are_w##c.related_share_w##c.mmunificence_w"
                  
                  . 
                  .   reghdfe `DV' `Model3' `controls' `EXTRA' i.fyear, vce (robust) absorb (gvkey fyear)
                  note: 6bn.related_serv_entry_years is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2002bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2003bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2004bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2005bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2006bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2007bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2008bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2009bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2010bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2011bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2012bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2013bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2014bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2015bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2016bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2017bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2018bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  note: 2019bn.fyear is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
                  (MWFE estimator converged in 9 iterations)
                  note: related_share_w omitted because of collinearity
                  note: related_share_w omitted because of collinearity
                  note: 5.firstmover_related_years omitted because of collinearity
                  note: related_share_w omitted because of collinearity
                  note: 5.related_serv_entry_years omitted because of collinearity
                  note: 6.related_serv_entry_years omitted because of collinearity
                  note: 6.related_serv_entry_years#c.related_share_w omitted because of collinearity
                  note: 6.related_serv_entry_years#c.related_share_w#c.related_share_w omitted because of collinearity
                  note: related_share_w omitted because of collinearity
                  note: related_share_w omitted because of collinearity
                  note: related_share_w omitted because of collinearity
                  note: related_share_w omitted because of collinearity
                  note: related_share_w omitted because of collinearity
                  note: related_share_w omitted because of collinearity
                  note: 2002.fyear omitted because of collinearity
                  note: 2003.fyear omitted because of collinearity
                  note: 2004.fyear omitted because of collinearity
                  note: 2005.fyear omitted because of collinearity
                  note: 2006.fyear omitted because of collinearity
                  note: 2007.fyear omitted because of collinearity
                  note: 2008.fyear omitted because of collinearity
                  note: 2009.fyear omitted because of collinearity
                  note: 2010.fyear omitted because of collinearity
                  note: 2011.fyear omitted because of collinearity
                  note: 2012.fyear omitted because of collinearity
                  note: 2013.fyear omitted because of collinearity
                  note: 2014.fyear omitted because of collinearity
                  note: 2015.fyear omitted because of collinearity
                  note: 2016.fyear omitted because of collinearity
                  note: 2017.fyear omitted because of collinearity
                  note: 2018.fyear omitted because of collinearity
                  note: 2019.fyear omitted because of collinearity
                  
                  HDFE Linear regression                            Number of obs   =      6,986
                  Absorbing 2 HDFE groups                           F(  60,   6148) =      10.01
                                                                    Prob > F        =     0.0000
                                                                    R-squared       =     0.7065
                                                                    Adj R-squared   =     0.6665
                                                                    Within R-sq.    =     0.0966
                                                                    Root MSE        =     0.4238
                  
                  ------------------------------------------------------------------------------------------------------------------------------
                                                                               |               Robust
                                                                    tobinq3_ln | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
                  -------------------------------------------------------------+----------------------------------------------------------------
                                                     1.firstmover_related_sic4 |   .0935945   .1075539     0.87   0.384    -.1172489    .3044379
                                                          1.related_serv_entry |  -.0404836   .0486961    -0.83   0.406     -.135945    .0549777
                                                               related_share_w |   .7198769   .3991268     1.80   0.071    -.0625512    1.502305
                                                                               |
                                           c.related_share_w#c.related_share_w |  -3.768495   .8939441    -4.22   0.000    -5.520938   -2.016052
                                                                               |
                                                         related_invest_firm_w |  -2.993201   3.172654    -0.94   0.345    -9.212714    3.226312
                                                                               |
                                     c.related_share_w#c.related_invest_firm_w |   24.84566   10.48792     2.37   0.018     4.285655    45.40566
                                                                               |
                   c.related_share_w#c.related_share_w#c.related_invest_firm_w |  -24.75243   7.969598    -3.11   0.002    -40.37563   -9.129225
                                                                               |
                                                               related_share_w |          0  (omitted)
                                                                  serv_share_w |  -.3357782   .1037478    -3.24   0.001    -.5391603   -.1323961
                                                                               |
                                              c.related_share_w#c.serv_share_w |   2.154042   .6616717     3.26   0.001     .8569343    3.451151
                                                                               |
                            c.related_share_w#c.related_share_w#c.serv_share_w |   1.432156   .8414135     1.70   0.089    -.2173091     3.08162
                                                                               |
                                                               related_share_w |          0  (omitted)
                                                                               |
                                                      firstmover_related_years |
                                                                            1  |  -.2049543   .1767122    -1.16   0.246    -.5513721    .1414635
                                                                            2  |  -.0265078   .1371892    -0.19   0.847    -.2954467     .242431
                                                                            3  |  -.1165556   .1197332    -0.97   0.330    -.3512745    .1181633
                                                                            4  |  -.1024822   .1254409    -0.82   0.414    -.3483903    .1434258
                                                                            5  |          0  (omitted)
                                                                               |
                                    firstmover_related_years#c.related_share_w |
                                                                            1  |   2.094874   1.457125     1.44   0.151    -.7616015    4.951349
                                                                            2  |   .9483689   1.343283     0.71   0.480    -1.684937    3.581674
                                                                            3  |   2.220298   1.200168     1.85   0.064     -.132451    4.573047
                                                                            4  |   1.732118   1.181625     1.47   0.143    -.5842799    4.048515
                                                                            5  |  -.0910074   .4485616    -0.20   0.839     -.970345    .7883303
                                                                               |
                  firstmover_related_years#c.related_share_w#c.related_share_w |
                                                                            1  |  -2.453687   2.679553    -0.92   0.360    -7.706549    2.799175
                                                                            2  |   -1.67494    2.71151    -0.62   0.537    -6.990449    3.640569
                                                                            3  |  -3.574963   2.280574    -1.57   0.117    -8.045685    .8957599
                                                                            4  |    -3.3133    2.48146    -1.34   0.182    -8.177829     1.55123
                                                                            5  |   .5795862   .7213243     0.80   0.422    -.8344619    1.993634
                                                                               |
                                                               related_share_w |          0  (omitted)
                                                                               |
                                                      related_serv_entry_years |
                                                                            1  |  -.0394245   .1193612    -0.33   0.741    -.2734143    .1945653
                                                                            2  |  -.0950138    .079206    -1.20   0.230    -.2502852    .0602577
                                                                            3  |  -.0778009   .0745037    -1.04   0.296    -.2238543    .0682524
                                                                            4  |  -.0847855   .0715974    -1.18   0.236    -.2251415    .0555706
                                                                            5  |          0  (omitted)
                                                                            6  |          0  (omitted)
                                                                               |
                                    related_serv_entry_years#c.related_share_w |
                                                                            1  |   .2849832   .6081283     0.47   0.639    -.9071611    1.477127
                                                                            2  |    .642178    .735333     0.87   0.383     -.799332    2.083688
                                                                            3  |   .6540408   .5149349     1.27   0.204    -.3554118    1.663493
                                                                            4  |   .9190708   .4309472     2.13   0.033     .0742635    1.763878
                                                                            5  |   .2770321   .2565122     1.08   0.280    -.2258216    .7798858
                                                                            6  |          0  (omitted)
                                                                               |
                  related_serv_entry_years#c.related_share_w#c.related_share_w |
                                                                            1  |  -1.068903   .7961736    -1.34   0.179    -2.629682    .4918762
                                                                            2  |  -.8762641   1.296204    -0.68   0.499    -3.417278    1.664749
                                                                            3  |  -.9876213    .799058    -1.24   0.217    -2.554055     .578812
                                                                            4  |  -1.415957   .6439586    -2.20   0.028    -2.678342   -.1535731
                                                                            5  |  -.6980355   .3816436    -1.83   0.067    -1.446191    .0501195
                                                                            6  |          0  (omitted)
                                                                               |
                                                               related_share_w |          0  (omitted)
                                                               related_speed_w |  -.1071793    .123158    -0.87   0.384    -.3486121    .1342535
                                                                               |
                                           c.related_share_w#c.related_speed_w |   1.157657   .4298115     2.69   0.007     .3150761    2.000238
                                                                               |
                         c.related_share_w#c.related_share_w#c.related_speed_w |  -.7621851   .4220848    -1.81   0.071    -1.589619    .0652488
                                                                               |
                                                               related_share_w |          0  (omitted)
                                                                     rslack2_w |   .4745646   .0811247     5.85   0.000     .3155317    .6335975
                                                                               |
                                                 c.related_share_w#c.rslack2_w |  -1.349534   .3784196    -3.57   0.000    -2.091369   -.6076994
                                                                               |
                               c.related_share_w#c.related_share_w#c.rslack2_w |   2.162104    .548461     3.94   0.000     1.086928    3.237279
                                                                               |
                                                               related_share_w |          0  (omitted)
                                                                      advint_w |  -1.136967   .5649116    -2.01   0.044    -2.244392   -.0295427
                                                                               |
                                                  c.related_share_w#c.advint_w |  -12.14579    2.86489    -4.24   0.000    -17.76198   -6.529608
                                                                               |
                                c.related_share_w#c.related_share_w#c.advint_w |   27.43457   4.955688     5.54   0.000     17.71969    37.14945
                                                                               |
                                                               related_share_w |          0  (omitted)
                                                                     mgrowth_w |   .1269538    .072271     1.76   0.079    -.0147226    .2686301
                                                                               |
                                                 c.related_share_w#c.mgrowth_w |   .8146096    .376748     2.16   0.031     .0760517    1.553167
                                                                               |
                               c.related_share_w#c.related_share_w#c.mgrowth_w |  -1.516635   .4941099    -3.07   0.002    -2.485263   -.5480063
                                                                               |
                                                               related_share_w |          0  (omitted)
                                                                  mdynamism1_w |   .3612269   .1230004     2.94   0.003     .1201029    .6023508
                                                                               |
                                              c.related_share_w#c.mdynamism1_w |   .6950912   .7363864     0.94   0.345    -.7484837    2.138666
                                                                               |
                            c.related_share_w#c.related_share_w#c.mdynamism1_w |  -2.574078   1.010927    -2.55   0.011    -4.555849    -.592308
                                                                               |
                                                               related_share_w |          0  (omitted)
                                                                mmunificence_w |   .1310989   .1296821     1.01   0.312    -.1231234    .3853212
                                                                               |
                                            c.related_share_w#c.mmunificence_w |   .9417028   .7312341     1.29   0.198    -.4917719    2.375178
                                                                               |
                          c.related_share_w#c.related_share_w#c.mmunificence_w |  -2.035899   1.016174    -2.00   0.045    -4.027956   -.0438429
                                                                               |
                                                                        emp_ln |  -.1372171   .0246168    -5.57   0.000    -.1854746   -.0889595
                                                                         roa_w |   .2192622   .0467106     4.69   0.000     .1276931    .3108314
                                                                total_divers_w |  -.0213847   .0383543    -0.56   0.577    -.0965725    .0538032
                                                                        mint_w |   .7614987   .0749445    10.16   0.000     .6145812    .9084163
                                                                               |
                                                                         fyear |
                                                                         2002  |          0  (omitted)
                                                                         2003  |          0  (omitted)
                                                                         2004  |          0  (omitted)
                                                                         2005  |          0  (omitted)
                                                                         2006  |          0  (omitted)
                                                                         2007  |          0  (omitted)
                                                                         2008  |          0  (omitted)
                                                                         2009  |          0  (omitted)
                                                                         2010  |          0  (omitted)
                                                                         2011  |          0  (omitted)
                                                                         2012  |          0  (omitted)
                                                                         2013  |          0  (omitted)
                                                                         2014  |          0  (omitted)
                                                                         2015  |          0  (omitted)
                                                                         2016  |          0  (omitted)
                                                                         2017  |          0  (omitted)
                                                                         2018  |          0  (omitted)
                                                                         2019  |          0  (omitted)
                                                                               |
                                                                         _cons |   .3836073   .0702962     5.46   0.000     .2458022    .5214123
                  ------------------------------------------------------------------------------------------------------------------------------
                  
                  Absorbed degrees of freedom:
                  -----------------------------------------------------+
                   Absorbed FE | Categories  - Redundant  = Num. Coefs |
                  -------------+---------------------------------------|
                         gvkey |       760           0         760     |
                         fyear |        19           1          18     |
                  -----------------------------------------------------+
                  
                  .   
                  .

                  Comment


                  • #10
                    Originally posted by Kseniya Levykina View Post
                    Could it be that the use of "##" instead of "#" in the model definition "c.related_share_w##c.related_share_w##" + ME several times could be causing an issue?.. Especially taking into account that variable sequence in the model definition matters.
                    In your full dataset, the variable is not omitted so there is no collinearity. But you state that

                    In the loop it starts though sometimes to get ommited completely and so far I could see
                    Just run that regression outside the loop and see whether the variable is omitted. It is almost impossible to be more helpful without having access to your dataset as a lot of your results are not replicable with a smaller sample. Are you able to share your full dataset? If so, you can send it as an email attachment and I can have a look.

                    Comment


                    • #11
                      I was running different model options multiple hours now trying to pinpoint what is causing the issue, I have concluded the following:

                      1. Looks like I have finally found what was causing the main issue with plots - category moderator i.related_serv_entry_years. Without it everything works (also inside the loop). Not sure why - if the moderator is insignificant and sometimes even omitted, I would not expect it affect all the rest moderating effects and their plotting... It may be though due to existing correlation between it and my main IV of ca. 50% (??)

                      2. Even outside the loop after running the model the related_share_w values get hard-rewritten sometimes - it happens though in an inconsistent way (really out of the blue - sometimes directly after 1 run, sometimes I have no issues for very long)... No code appears doing this in the output - neither I ask for it. Makes me worry a bit going forward using Stata as I am obviously not re-checking every time all variables for changes...
                      So from this state:

                      Code:
                      .     summarize related_share_w
                      
                          Variable |        Obs        Mean    Std. dev.       Min        Max
                      -------------+---------------------------------------------------------
                      related_sh~w |      6,986    .3160973    .2411776          0          1
                      the IV becomes sometimes to be this:

                      Code:
                      summarize related_share_w
                      
                          Variable |        Obs        Mean    Std. dev.       Min        Max
                      -------------+---------------------------------------------------------
                      related_sh~w |      6,986    .0749197           0   .0749197   .0749197
                      And then of course no plotting is possible anymore

                      Is there maybe some function to "protect" the whole dataset from any changes? I could not find something like this. I was trying also to drop the stored data in r() (with "mata : st_rclear()") - this didnt help to stop the issue from appearing again.

                      I suspect it is caused by the local variables in combination with unsuccessful marginplotting (when i.related_serv_entry_years is in play), but cannot get my mind over where exactly and why... But at least the model and plots work again

                      Andrew Musau, if you have a chance to explore this mystery, happy to share the dataset with you via email. Just let me know the address.
                      In any way, thank you very much for helping me to find the way out here, super appreciated!

                      Comment


                      • #12
                        The issue that I see is that your marginal effects are not estimable, which should have been apparent if you got rid of the capture commands as I advised in #3. You have very long and complex models. If you simplify, (e.g., model 3 below), you will see that you can estimate the marginal effects and a graph is generated. So you have to check what are the problematic indicators causing this issue. If you have no clue, add one variable at a time starting from the simplified model and successively run margins to see where it chokes. Here is an example of code that shows this.


                        Code:
                        *MARGINS NOT ESTIMABLE (PRODUCES EMPTY GRAPH)
                        
                        xtset gvkey fyear
                        
                        local DVs "tobinq3_ln" // could be switched to several - to simplify for now just 1
                        local controls "c.emp_ln c.roa_w c.total_divers_w"
                        local EXTRAs "c.mint_w" // could be switched to several - to simplify for now just 1
                        
                        xtreg tobinq3_ln `Model3' c.emp_ln c.roa_w c.total_divers_w c.mint_w i.fyear, fe vce (robust)
                        
                        
                        local Model3 "i.firstmover_related_sic4 i.related_serv_entry c.related_share_w##c.related_share_w##c.related_invest_firm_w c.related_share_w##c.related_share_w##c.serv_share_w c.related_share_w##c.related_share_w##i.firstmover_related_years c.related_share_w##c.related_share_w##i.related_serv_entry_years c.related_share_w##c.related_share_w##c.related_speed_w c.related_share_w##c.related_share_w##c.rslack2_w c.related_share_w##c.related_share_w##c.advint_w c.related_share_w##c.related_share_w##c.mgrowth_w c.related_share_w##c.related_share_w##c.mdynamism1_w c.related_share_w##c.related_share_w##c.mmunificence_w"
                        
                        foreach DV of local DVs {
                            foreach EXTRA of local EXTRAs {
                            local Mymodel "FEr-yd-6"
                            forv i = 3/3 {
                         
                            xtreg `DV' `Model`i'' `controls' `EXTRA' i.fyear, fe vce (robust)
                                summarize related_share_w
                                local MyMin = max((r(mean) - r(sd)),r(min))
                                local MyMax = min((r(mean) + r(sd)),r(max))
                                local Grid = (`MyMax'-`MyMin')/10
                            
                            
                                quietly summarize c.related_invest_firm_w
                                local MyMin2 = max((r(mean) - r(sd)),r(min))
                                local MyMax2 = min((r(mean) + r(sd)),r(max))
                                local Grid2 = (`MyMax2'-`MyMin2')/2
                                
                                // creating first margin plot - Modearting effect
                        margins, at(c.related_share_w=(`MyMin' (`Grid') `MyMax') c.related_invest_firm_w=(`MyMin2' (`Grid2') `MyMax2'))
                                
                         marginsplot, recast(line) noci title("Moderating effect of `cME'") xtitle("Service relatedness") ytitle("Firm performance: `DV'") xlabel(, angle(45) format(%5.2f)) plot1opts(lcolor(black)) plot2opts(lcolor(gs6) lpattern("--")) legend(on order(1 "low level `cME'" 2 "medium level `cME'" 3 "high level `cME'"))  
                                }
                            }
                        }
                        Partial Res.:

                        Code:
                        32._at       : related_sh~w    =    .5572749
                                       related_in~w    =    .0141791
                        
                        33._at       : related_sh~w    =    .5572749
                                       related_in~w    =    .0283582
                        
                        ------------------------------------------------------------------------------
                                     |            Delta-method
                                     |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
                        -------------+----------------------------------------------------------------
                                 _at |
                                  1  |          .  (not estimable)
                                  2  |          .  (not estimable)
                                  3  |          .  (not estimable)
                                  4  |          .  (not estimable)
                                  5  |          .  (not estimable)
                                  6  |          .  (not estimable)
                                  7  |          .  (not estimable)
                                  8  |          .  (not estimable)
                                  9  |          .  (not estimable)
                                 10  |          .  (not estimable)
                                 11  |          .  (not estimable)

                        Code:
                        *SIMPLIFIED MODEL, MARGINS ESTIMABLE, GENERATES GRAPH
                        xtset gvkey fyear
                        
                        local DVs "tobinq3_ln" // could be switched to several - to simplify for now just 1
                        local controls "c.emp_ln c.roa_w c.total_divers_w"
                        local EXTRAs "c.mint_w" // could be switched to several - to simplify for now just 1
                        
                        foreach DV of local DVs {
                            foreach EXTRA of local EXTRAs {
                            local Mymodel "FEr-yd-6"
                            forv i = 3/3 {
                         
                        xtreg tobinq3_ln i.firstmover_related_sic4 i.related_serv_entry related_share_w c.related_share_w#c.related_share_w related_invest_firm_w ///
                        c.related_share_w#c.related_invest_firm_w c.related_share_w#c.related_share_w#c.related_invest_firm_w serv_share_w c.related_share_w#c.serv_share_w ///
                        c.related_share_w#c.related_share_w#c.serv_share_w i.firstmover_related_years i.firstmover_related_years#c.related_share_w, fe vce (robust)
                                summarize related_share_w
                                local MyMin = max((r(mean) - r(sd)),r(min))
                                local MyMax = min((r(mean) + r(sd)),r(max))
                                local Grid = (`MyMax'-`MyMin')/10
                            
                            
                                quietly summarize c.related_invest_firm_w
                                local MyMin2 = max((r(mean) - r(sd)),r(min))
                                local MyMax2 = min((r(mean) + r(sd)),r(max))
                                local Grid2 = (`MyMax2'-`MyMin2')/2
                                
                                // creating first margin plot - Modearting effect
                        margins, at(c.related_share_w=(`MyMin' (`Grid') `MyMax') c.related_invest_firm_w=(`MyMin2' (`Grid2') `MyMax2'))
                                
                        marginsplot, recast(line) noci title("Moderating effect of `cME'") xtitle("Service relatedness") ytitle("Firm performance: `DV'") xlabel(, angle(45) format(%5.2f)) plot1opts(lcolor(black)) plot2opts(lcolor(gs6) lpattern("--")) legend(on order(1 "low level `cME'" 2 "medium level `cME'" 3 "high level `cME'"))    
                                }
                            }
                        }
                        Partial Res.:

                        Code:
                        31._at       : related_sh~w    =    .5572749
                                       related_in~w    =           0
                        
                        32._at       : related_sh~w    =    .5572749
                                       related_in~w    =    .0141791
                        
                        33._at       : related_sh~w    =    .5572749
                                       related_in~w    =    .0283582
                        
                        ------------------------------------------------------------------------------
                                     |            Delta-method
                                     |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
                        -------------+----------------------------------------------------------------
                                 _at |
                                  1  |   .5083546   .0506249    10.04   0.000     .4091316    .6075775
                                  2  |   .4977271   .0642028     7.75   0.000      .371892    .6235622
                                  3  |   .4870996   .1010153     4.82   0.000     .2891134    .6850859
                                  4  |   .5455008   .0471965    11.56   0.000     .4529974    .6380042
                                  5  |   .5469844   .0556653     9.83   0.000     .4378825    .6560864
                                  6  |    .548468   .0841917     6.51   0.000     .3834554    .7134807
                                  7  |    .567799   .0448652    12.66   0.000     .4798649     .655733
                                  8  |   .5803298   .0495151    11.72   0.000      .483282    .6773776
                                  9  |   .5928606   .0704584     8.41   0.000     .4547646    .7309566
                                 10  |   .5752489    .041968    13.71   0.000     .4929931    .6575047
                        Click image for larger version

Name:	Graph.png
Views:	1
Size:	59.8 KB
ID:	1651241

                        Last edited by Andrew Musau; 21 Feb 2022, 16:16.

                        Comment


                        • #13
                          Thank you very much for looking into this, Andrew! I definitely have learned a lot.

                          On my end I was unfortunately noticing this "(not estimable)" picture only in combination with the issue of "related_share_w" being rewritten to a constant value... You have not experienced this, have you?

                          I have not expected that adding extra variables (esp. those that are omitted or insignificant) could affect not just the way the ME plotting of previously existing significant variables look like (what I was anticipating), but also if it can be estimated and plotted at all. Interesting.

                          Comment


                          • #14
                            Originally posted by Kseniya Levykina View Post

                            On my end I was unfortunately noticing this "(not estimable)" picture only in combination with the issue of "related_share_w" being rewritten to a constant value... You have not experienced this, have you?
                            No, I am using your commands from #1, and there is nothing there that is modifying the data. You need to check whether you have any replace commands in your do-file, otherwise estimation and post-estimation commands would normally not modify your variables. One other thing I forgot to mention, you can use the option -noestimcheck- to suppress estimability checks. Doing this will give you results, and margins proceeds as if the marginal effects were estimable.


                            Code:
                            margins, at(c.related_share_w=(`MyMin' (`Grid') `MyMax') `cME'=(`MyMin2' (`Grid2') `MyMax2')) noestimcheck

                            Comment


                            • #15
                              Thank you, Andrew! Will try it out.

                              Comment

                              Working...
                              X