Announcement

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

  • #16
    Dear Andrew,

    I have indeed tried the code line by line but I do not know how to amend it so that in each column instead of adding just one control variable I can add a group. In particular, column 1 should not have any controls, column 2 should have the control variables "gdpgrowth" and "inflation", column 3 should have the control variables in column 2 + the control variables "agegroup" and "immigration", and column 4 should have the control variables in column 3 + the control variables "construction" and "agriculture".

    Thank you very much again for all your help,

    Joan

    Comment


    • #17
      I see that I misread your question in #14. Store the list of controls in separate locals and then refer to a specific local in the loop.

      Code:
      webuse grunfeld, clear
      set seed 08082020
      
      forval i=1/9{
          gen var`i'= runiformint(0, `i'00)
      }
      local controls1 var1 var2 var3
      local controls2 var1 var2 var3 var4 var5 var6
      local controls3 var1 var2 var3 var4 var5 var6 var7 var8 var9
      eststo clear
      forval c=0/3{
          local control=cond(`c'==0, "",  "`controls`c''")
          xtreg mvalue c.invest#i.year c.invest i.year `control', fe
          local r2=e(r2)
          local list
          forval y= 1936/ 1954{
              local list "`list' (year`y'=invest+`y'.year#c.invest)"
          }
          xlincom `list', post
          eststo est`c'
          estadd local r2= round(`r2', .001)
      }
      esttab est*, stats(N r2, labels("Observations" "R-squared")) mlabel(none)
      Last edited by Andrew Musau; 08 Aug 2020, 14:31.

      Comment


      • #18
        Thank you very much Andrew, this works well but out of the 4 years in my dataset that I calculate this for, 3 show identical coefficients, standard errors, t-stats and p values. Can this be correct? I think it is using the same control variables throughout those three. Below is my specific code, following yours above:


        forval i=1/10{
        gen var`i'= runiformint(0, `i'00)
        }
        local controls1 gdpgrowth unemployment
        local controls2 immigration males workage
        local controls3 lessprim secondary tertiary
        local controls4 indprod constrprod
        eststo clear
        forval c=0/4{
        local control=cond(`c'==0, "", "`controls`c''")
        xtreg yvariable c.xvariable#i.year c.xvariable i.year `control', fe
        local r2=e(r2)
        local list
        forval y= 2002 2006: 2014{
        local list "`list' (year`y'=c.xvariable+`y'.year#c.xvariable)"
        }
        xlincom `list', post
        eststo est`c'
        estadd local r2= round(`r2', .001)
        }
        esttab est* using regression5.tex, stats(N r2, labels("Observations" "R-squared")) mlabel(none) star(* 0.10 ** 0.05 *** 0.01) replace


        Therefore, I show coefficients for 2002, 2006, 2010, 2014. However, all coefficients, standard errors etc. for 2002, 2006 and 2014 are identical.

        Thank you again for all the help,

        Joan

        Comment


        • #19
          #1
          forval i=1/10{
          gen var`i'= runiformint(0, `i'00)
          }

          local controls1 gdpgrowth unemployment
          local controls2 immigration males workage
          local controls3 lessprim secondary tertiary
          local controls4 indprod constrprod
          This initial loop in my code is to create the controls. It serves no practical purpose in your code.

          #2
          From your description in #16, your locals are incremental but you do not define them in this way in #18. What you should have is:

          Code:
          local controls1 gdpgrowth unemployment
          local controls2 gdpgrowth unemployment immigration males workage
          local controls3 gdpgrowth unemployment immigration males workage lessprim secondary tertiary
          local controls4 gdpgrowth unemployment immigration males workage lessprim secondary tertiary indprod constrprod

          The rest, you have to manually inspect whether the regressions are what you expect them to be. If you have a lot of variables in the model, adding more variables may not change the coefficients and standard errors of your existing variables much. I can work with what I see, so I cannot diagnose problems that arise from data and output that I have no access to. What I know is that the problems that you report do not arise in the example in #17.

          Comment


          • #20
            Dear Andrew, I checked manually one by one all regressions and it seems the problem is that coefficients for all years except 2010 are omitted because of collinearity in the interaction term "c.xvariable#i.year", but do show coefficients in the "i.year" fixed effects part. Is there something I am doing wrong? Should I not include the variable "year" both in "c.xvariable#i.year" and by itself in "i.year"?

            If my regression is: xtreg yvariable c.xvariable#i.year c.xvariable i.year `control', fe

            And I want to understand the impact that xvariable has on yvariable broken down by year, the calculation "year`y'=c.xvariable+`y'.year#c.xvariable" is the correct one right? Or do I have to add the coefficients of "i.year" too?

            Thank you very much,

            Joan

            Last edited by Joan Marti; 10 Aug 2020, 03:18.

            Comment


            • #21
              Now your issue is no longer one of coding but model specification. I suggest that you start a new thread appropriately titled asking that specific question. A tip is to figure out the econometric part before going into coding.

              Comment


              • #22
                Thank you Andrew, I will do that. Thanks a lot again for all of your help, it has been extremely useful.

                Joan

                Comment


                • #23
                  Hi Andrew, estimating the coefficients with margins instead of the above calculation I get different results, and they are not all equal anymore. Is this normal, or is there an error in the codes above?

                  The codes I am using are:

                  xtreg yvariable c.xvariable##i.year, fe
                  margins, dydx(xvariable) at(year = (2002 2006 2010 2014))

                  Best regards,

                  Joan



                  Comment


                  • #24
                    The marginal effect in your expression is the estimated coefficient on the independent variable + the coefficient on the interaction with year.

                    Code:
                    webuse grunfeld
                    xtreg invest c.mvalue##i.year, fe
                    margins, dydx(mvalue) at(year = (1945 1946 1947 1948))
                    forval y=1945/1948{
                        di _b[mvalue]+ _b[`y'.year#c.mvalue]
                    }
                    Res.:

                    Code:
                    . margins, dydx(mvalue) at(year = (1945 1946 1947 1948))
                    
                    Average marginal effects                        Number of obs     =        200
                    Model VCE    : Conventional
                    
                    Expression   : Linear prediction, predict()
                    dy/dx w.r.t. : mvalue
                    
                    1._at        : year            =        1945
                    
                    2._at        : year            =        1946
                    
                    3._at        : year            =        1947
                    
                    4._at        : year            =        1948
                    
                    ------------------------------------------------------------------------------
                                 |            Delta-method
                                 |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                    mvalue       |
                             _at |
                              1  |   .0877504   .0217357     4.04   0.000     .0451492    .1303515
                              2  |    .117177   .0212688     5.51   0.000     .0754909    .1588631
                              3  |   .1313237     .02923     4.49   0.000     .0740339    .1886134
                              4  |   .1379082   .0319931     4.31   0.000     .0752029    .2006135
                    ------------------------------------------------------------------------------
                    
                    . 
                    . forval y=1945/1948{
                      2. 
                    .     di _b[mvalue]+ _b[`y'.year#c.mvalue]
                      3. 
                    . }
                    .08775038
                    .11717699
                    .13132366
                    .13790818

                    Comment

                    Working...
                    X