Announcement

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

  • Plotting/graph question

    Hello,

    I am currently learning how to work with Generalized Additive Models (GAMs).
    I found the following exercise in an old Stata Technical Bulletin:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	114.1 KB
ID:	165774

    Now, producing the model is pretty straightforward, but I was wondering how to get this graph.
    I have been searching a bit online for how to do this, but most (introductory) manuals simply explain how to produce a straight "trendline", not the ones shown above.
    I have very limited experience in visualizing my results.

    Thank you for your help,

    Willem

  • #2
    Willem, once you have the model, you just plot the fitted values. Best, Sergiy

    Code:
    clear all
    sysuse auto
    logit foreign mpg
    predict hat
    label variable hat "Predicted probability of foreign"
    twoway scatter foreign mpg || line hat mpg,sort
    Click image for larger version

Name:	pr_foreign.png
Views:	1
Size:	11.5 KB
ID:	166029

    Comment


    • #3
      Originally posted by Sergiy Radyakin View Post
      Willem, once you have the model, you just plot the fitted values. Best, Sergiy

      Code:
      clear all
      sysuse auto
      logit foreign mpg
      predict hat
      label variable hat "Predicted probability of foreign"
      twoway scatter foreign mpg || line hat mpg,sort
      [ATTACH=CONFIG]n166029[/ATTACH]

      Hey Sergiy,

      Thank you for your reply.
      I have tried this, but I get the following error message after having run the predict command: "last estimates not found".

      My code is:
      Code:
      gam growth debt, df(5)
      predict predgrowth
      label variable predgrowth "Predicted growth"
      twoway scatter growth debt || line predgrowth debt,sort
      What am I doing wrong?

      Comment


      • #4
        Not reading the help carefully....

        gam creates a new variable GAM_mu containing the fitted values on the scale of the response variable.
        gam (STB-42) is a rather old and non-standard program. Evidently it doesn't support predict, as is now fairly standard for programs of its kind. But the help explains that it leaves predicted values in memory in a new variable, which is what you need here.

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Not reading the help carefully....



          gam (STB-42) is a rather old and non-standard program. Evidently it doesn't support predict, as is now fairly standard for programs of its kind. But the help explains that it leaves predicted values in memory in a new variable, which is what you need here.
          Thanks. It works now!

          Comment

          Working...
          X