Announcement

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

  • Plotting a fitted Line for log scale axis

    Hello,

    I have to plot a simple fitted line for exports relative to GDP (the variable is called "norm_exports") on the y axis and bilateral distance (variable "km") on the x axis. However, I am having problems, since I have to depict the y axis in log scale. I know that I can therefore not use the standard twoway lfit command:

    twoway (scatter norm_exports km)(lfit norm_exports km)

    Therefore I tried to use predict for a regression of the log of my export variable on distance:

    quietly reg log_norm_exports km

    predict gr

    label var gr "Linear prediction"

    twoway (scatter norm_exports km)(line gr km, sort), yscale(log)

    However, the code I used is not working. I would be really thankful if one could tell me where my mistake was.

    Thanks a lot.

  • #2
    Perhaps you need either


    Code:
    quietly reg log_norm_exports km
    predict gr
    * !!! or 10^gr if you used log10() to generate log_norm_exports 
    replace gr = exp(gr) 
    twoway (scatter norm_exports km)(line gr km, sort), yscale(log)
    or

    Code:
    quietly poisson norm_exports km  
    predict gr
    twoway (scatter norm_exports km)(line gr km, sort), yscale(log)
    Code:
    
    
    -- noting that these are not exactly the same. Usually the second is a better idea. The fallacy in your code is that ysc(log) is fine for your data, but your predictions are already on log scale and not commensurate.


    Comment

    Working...
    X