Announcement

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

  • Deriving vertex co-ordinates from a qfit plot

    Hi everyone,

    I'm new to Stata so please forgive me if I get any of my terms wrong. I've generated qfit plots to visualise the relationship between my dependent and independent variables (two-way qfit y x) but now i want to determine the co-ordinates of the vertex. I can do this manually by regressing the variables (regress y x x^2) to generate coefficients and then calculate the x value for the vertex using '-linear coefficient/(2xquadratic coefficient)' and lastly calculate the y value by inserting the x value back into the regression derived quadratic equations. However, i have 20 qfits so this will take hours. Is there any shortcut for this in stata?

    Many thanks

    Jay

    Edit- I'm using small stata v14.2


    Last edited by Jay Tanner; 04 May 2017, 06:33.

  • #2
    A loop is in order here, the exact form of which would depend on the nature of your list of x and y variables and possibly what you want to do with these results after you get them. Here's an illustration of one way to do this. I didn't check the results at all carefully, so you will want to check some examples by hand:
    Code:
    sysuse auto
    local y = price
    foreach x of varlist weight displacement length {
       regress price c.`x'##c.`x'
       local b1 = el(r(table),1,1)
       local b2 = el(r(table),1,2)
       local a = el(r(table),1,3)
       local xval = -`b1'/(2*`b2')
       local yval = `a' + `b1' * `xval' + `b2' * `xval'^2
       display "xvar = `x'; x, y = " `xval' ", " `yval'
    }

    Comment


    • #3
      Thank you very much!

      Comment

      Working...
      X