Announcement

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

  • How to fix a kink in lfit using tw graph

    Hello,

    I am trying to produce a tw graph. I want to create a linear fit, but I see a "kink" in the middle of the line, opposed to what I would expect --- a simple straight line.
    To give you an idea, my graph currently looks like this:
    arntz_relwage_allcountries_lfit.png

    My code is the following:
    Code:
    tw (scatter arntz_auto relwage if isco1d==1, xsc(log) msymbol(circle) mfc(none)) ///
               (scatter auto rw if isco1d==2, xsc(log) msymbol(square) mfc(none)) ///
               (scatter auto rw if isco1d==3, xsc(log) msymbol(diamond) mfc(none)) ///
               (scatter auto rw if isco1d==4, xsc(log) msymbol(cross) mfc(none)) ///
               (scatter auto rw if isco1d==5, xsc(log) msymbol(triangle) mfc(none)) ///
               (scatter auto rw if isco1d==6, xsc(log) msymbol(circle) mfc(none)) ///
               (scatter auto rw if isco1d==7, xsc(log) msymbol(square) mfc(none)) ///
               (scatter auto rw if isco1d==8, xsc(log) msymbol(diamond) mfc(none)) ///
               (scatter auto rw if isco1d==9, xsc(log) msymbol(cross) mfc(none)) ///
               (lfit auto relwage if inlist(isco1d, 3,4,5,7,8,9),color(black) lwidth(vthin)), ///
                legend(order(1 2 3 4 5 7 8 9) label(1 "Manager") label(2 "Professionals") label(3 "Technicians") label(4 "Clerks") label(5 "Services and Sales") label(7 "Craft and Trades") label(8 "Plant and Machine") label(9 "Elementary")) ///
                ytitle("Automation Potential (Arntz et al)") xtitle("Relative Wage")
    How do I make the lfit straight?

    Thanks in advance.

  • #2
    lfit is just what it is: a way to put a linear fit through a scatter of points.

    If you want to fit a kinked line, use splines and regress. But I'll guess that you'll be better off with a logit model, depending on what the outcome is precisely.

    Comment


    • #3
      Thanks for your response, Nick.

      So I tried to regress it, then just plot the fitted line.
      When I just plot the line alone, it works fine.

      But, I'm having struggles trying to make the line show in the overlays of graphs using tw...

      Below is my code:

      Code:
      reg arntz_auto relwage if inlist(isco1d, 3, 4, 5, 7, 8, 9)
      predict linearreg, xb
      
      tw (scatter auto rw if isco1d==1, xsc(log) msymbol(circle) mfc(none) mlabel(country) mlabsize(vsmall)) ///
                 (scatter auto rw if isco1d==2, xsc(log) msymbol(square) mfc(none) mlabel(country) mlabsize(vsmall)) ///
                 (scatter auto rw if isco1d==3, xsc(log) msymbol(diamond) mfc(none) mlabel(country) mlabsize(vsmall)) ///
                 (scatter auto rw if isco1d==4, xsc(log) msymbol(cross) mfc(none) mlabel(country) mlabsize(vsmall)) ///
                 (scatter auto rw if isco1d==5, xsc(log) msymbol(triangle) mfc(none) mlabel(country) mlabsize(vsmall)) ///
                 (scatter auto rw if isco1d==6, xsc(log) msymbol(circle) mfc(none) mlabel(country) mlabsize(vsmall)) ///
                 (scatter auto rw if isco1d==7, xsc(log) msymbol(square) mfc(none) mlabel(country) mlabsize(vsmall)) ///
                 (scatter auto rw if isco1d==8, xsc(log) msymbol(diamond) mfc(none) mlabel(country) mlabsize(vsmall)) ///
                 (scatter auto rw if isco1d==9, xsc(log) msymbol(cross) mfc(none) mlabel(country) mlabsize(vsmall)) ///
                 (line linearreg rw), ///
                  legend(order(4 5 7 8 9) label(1 "") label(2 "") label(3 "") label(4 "Clerks") label(5 "Services and Sales") label(7 "Craft and Trades") label(8 "Plant and Machine") label(9 "Elementary")) ///
                  legend(rows(2)) ytitle("Automation Potential (Arntz et al)") xtitle("Relative Wage")

      Comment


      • #4
        Oh nevermind. I got it!
        I spotted a minor coding error.
        But thanks so much, Statalist community.

        Comment

        Working...
        X