Announcement

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

  • Difference between nlcom and margins

    Dear all,

    I am running the following regression;

    Code:
    svy linearized: tpoisson hours i.year_season i.location c.temp#i.location c.age##c.age* i.gender i.race i.health* c.income##c.income exp c.tar##c.tar
    My goal is to compute the turning point for the variable tar and I do so using;

    Code:
    nlcom -_b[tar]/(2*_b[c.tar#c.tar])
    However, I also compute the marginal effects using;

    Code:
    margins, at(tar = (12(1)43)) vsquish
    The output from margins shows that the point where hours is maximized is much lower (24 compared to 27 from nlcom). I am trying to understand where this difference comes from?

    Is there a way to reconcile the results from nlcom and margins? Any help will be greatly appreciated. Thank you!

    Sincerely,

    Milu

  • #2
    You didn't get a quick answer. I don't work with tpoisson or svy, but when I tried to replicate your problem, it did not work. Please start a new post including sample data using dataex so we can replicate your problem.

    Comment


    • #3
      Setting the -svy- part aside, you are neglecting that in Poisson models, you actually have E[y | x] = exp(a +b*x + c*x^2), so you are optimizing the wrong function by ignoring exp{} in your first calculation. Here's an example showing that the two ways agree:

      Code:
      webuse runshoes, clear
      tpoisson shoes c.age##c.age, coefl
      nlcom margins_at_age_16:exp(_b[_cons] +  _b[c.age]*16 + _b[c.age#c.age]*16^2)
      margins, at(age = (16(1)54))
      marginsplot, addplot(function exp(1.323112 -.0492211*x +  .0009251*x^2), range(16 54) lpatter(dash) lcolor(red)) xline(26.603) noci
      Last edited by Dimitriy V. Masterov; 22 Jun 2018, 13:01.

      Comment


      • #4
        Dear Dimitriy V. Masterov, thank you very much for your reply and the solution. Your code is very useful!

        I had a question about the following part;
        Code:
        nlcom margins_at_age_16:exp(_b[_cons] +  _b[c.age]*16 + _b[c.age#c.age]*16^2)
        why multiplying by 16 though? Thanks again!

        Sincerely,

        Chiara

        Comment


        • #5
          I am calculating predicted shoes at age 16, so it matches the first margins.

          Comment


          • #6
            Dear Dimitriy V. Masterov, thank you so much! Appreciate it.

            Sincerely,

            Chiara

            Comment

            Working...
            X