Announcement

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

  • How to generate cubic turning points?

    Esteemed Statalisters,

    Please I use Stata 16 and need your assistance with deriving cubic turning points.

    This is my model specification:

    lnAero = b0 + b1lnfyb + b2lnfyb^2 + b3lnfyb^3 + b4lntrade + u

    Does anyone know the Stata syntax to obtain the turning points of FYB?

    Any help will be greatly appreciated.

    Thanks in advance,
    Ngozi

  • #2
    Well, this is a calculus problem. The turning points are where dlnAero/dlnfyb = 0. The derivative of your expression is 3*b3*lnfyb^2 + 2*b2*lnfyb + b1. We can set that equal to zero and solve using the quadratic formula to find the roots:

    lnfyb = [-2*b2 +or- sqrt(4*b2^2-12*b3*b1)]/(6*b3)

    If you just need the turning points themselves, I would calculate that by storing the estimates for b1, b2, and b3 as scalars or local macros and then just calculate that expression. If you also need standard errors for the turning points, then you will have to use -nlcom-. In principle that's the same thing, but you'll have to work with the _b[] expressions in -nlcom-, so that's a lot of typing.

    Added: And bear in mind that not all cubics have turning points. You could end up with no solutions.
    Last edited by Clyde Schechter; 06 Oct 2021, 15:57.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Well, this is a calculus problem. The turning points are where dlnAero/dlnfyb = 0. The derivative of your expression is 3*b3*lnfyb^2 + 2*b2*lnfyb + b1. We can set that equal to zero and solve using the quadratic formula to find the roots:

      lnfyb = [-2*b2 +or- sqrt(4*b2^2-12*b3*b1)]/(6*b3)

      If you just need the turning points themselves, I would calculate that by storing the estimates for b1, b2, and b3 as scalars or local macros and then just calculate that expression. If you also need standard errors for the turning points, then you will have to use -nlcom-. In principle that's the same thing, but you'll have to work with the _b[ ] expressions in -nlcom-, so that's a lot of typing.

      Added: And bear in mind that not all cubics have turning points. You could end up with no solutions.
      Thanks, Prof. Schechter for the prompt response.
      But I don't know how to store the estimates of the betas as scalars.
      Please help me with the code to use.
      Thanks.
      Ngozi

      Comment


      • #4
        Well, it depends on the exact coding of the regression model. Let's say you use:

        Code:
        regress lnAero = c.lnfyb##c.lnfyb##c.lnfyb lntrade
        Then you would follow with:
        Code:
        scalar b1 = _b[mpg]
        scalar b2 = _b[c.mpg#c.mpg]
        scalar b3 = _b[c.mpg#c.mpg#c.mpg]
        scalar turning_point_1 = (-2*b2 + sqrt(4*b2^2 - 12*b3*b1))/6*b3)
        scalar turning_point_2 = (-2*b2 - sqrt(4*b2^2 - 12*b3*b1))/6*b3)
        display turning_point_1, turning_point_2
        Read -help scalar- to learn more about creating and using scalars. Do be warned: scalar names can clash with variable names. So if you already have any variables named b1, b2, b3, turning_point_1, or turning_point_2, then either rename those variables or choose different names for these scalars.

        Comment


        • #5
          Originally posted by Clyde Schechter View Post
          Well, it depends on the exact coding of the regression model. Let's say you use:

          Code:
          regress lnAero = c.lnfyb##c.lnfyb##c.lnfyb lntrade
          Then you would follow with:
          Code:
          scalar b1 = _b[mpg]
          scalar b2 = _b[c.mpg#c.mpg]
          scalar b3 = _b[c.mpg#c.mpg#c.mpg]
          scalar turning_point_1 = (-2*b2 + sqrt(4*b2^2 - 12*b3*b1))/6*b3)
          scalar turning_point_2 = (-2*b2 - sqrt(4*b2^2 - 12*b3*b1))/6*b3)
          display turning_point_1, turning_point_2
          Read -help scalar- to learn more about creating and using scalars. Do be warned: scalar names can clash with variable names. So if you already have any variables named b1, b2, b3, turning_point_1, or turning_point_2, then either rename those variables or choose different names for these scalars.
          Thanks so much, Prof Schechter.

          I will read up and try out the codes.

          Huge gratitude!!!

          Ngozi

          Comment

          Working...
          X