Announcement

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

  • Compute vertical distance betwen twoo line in a twoway line graph.... Seems easy? Not for me....

    Hi bros,

    I'm sorry if my question feels obvious for you but i need an answer.
    Basically, i need to compute the vertical distance between 2 lines of a twoway graph for each of my obs of one of the two lines (the red line).

    I give you a the command to reproduce the graph and data. I also attached the graph but it's my first message here so i still don't know if it will work.
    In the graph that i attached, i putted (with paint...) some vertical black lines who starts from one obs of the red line the the blue line (and not to an obs of the blue line), that's what i need to compute for each obs of the red line (year=2000).

    ***************************
    clear all
    set obs 40
    gen year=_n
    replace year=1000 if year>20
    replace year=2000 if year<21
    bysort year : gen age= _n + 49
    gen mortality=((age^5/age)/year^3)*100
    replace mortality= (1+mortality)^2 if year==2000
    gen employement=(((age^4)/(age^7))*100000)-((year^2)/40000000)
    replace year=1950 if year==1000
    twoway connected employement mortality if year==1950 ///
    || connected employement mortality if year==2000

    ************************

    As you can see, the mortality rates never matches between the 2 different years so...
    I cannot make a simple difference between the two employement of the two different years for the same mortality rates (because mortality rates never matches)

    Hope it was clear and that you will give me an easy solution for this.
    Thank you.

    PP.







    Attached Files
    0
    what is this?
    0%
    0
    why two?
    0%
    0

  • #2
    I think this should work:

    Code:
    reg em c.mor##c.mor##c.mor##c.mor##c.mor if year == 1950
    predict xb
    gen diff = emp - xb if year == 2000

    Comment


    • #3
      Thank you friend, that is exactly what i was looking for.

      Comment


      • #4
        Hi bros,

        Sorry, it's still me for the same issue…. Basically i was wrong; the solution Scott give me was very good but because my real data are not exactly the same of what i gave before … It doesn't work… I will try to join the real data in theattached "testi.txt"

        Okay here is why it doesn't work ; the data i gave before were very well approximated by a linear regression but my real data does not... so… It's not working anymore.
        In the graph 1.2
        you can see the relation between employment/mortalité with real data (green and blue lines). T
        here is also the prediction of a linear regression (same method Scott proposed me--> the red line).
        I want the exact value of the vertical difference between the 2 lines (the blue and green but not the red one). And i still have no idea how to do this…
        Again, i share the code so that, i hope, it will be easier for you.

        ****************************************
        clear all
        import delimited \"YOUR REPERTORY OF THE TXT"\testi.txt


        replace malemortality= malemortality*100
        replace femalemortality= femalemortality*100
        gen malemort1997=malemortality if year==1997
        gen malemort2008=malemortality if year==2008
        line malemort1997 malemort2008 age
        drop if age>69

        gen age2=age if age==50
        replace age2=age if age==55
        replace age2=age if age==60
        replace age2=age if age==65
        replace age2=age if age==70

        twoway connected travmale malemortality if age<70 & year==1997, mlabel(age2) ///
        || connected travmale malemortality if age<70 & year==2008, mlabel(age2) /// ///
        ytitle("Taux d'Emploi") xline(0.497) xline(2.1891) xtitle("Taux de Mortalité (%)") title("Relation emploi/mortalité en Belgique") ///
        legend(position(6) col(2) ///
        order(1 "1997" ///
        2 "2008"))


        reg travmale c.malemortality##c.malemortality##c.malemortality# #c.malemortality##c.malemortality##c.malemortality ##c.malemortality##c.malemortality
        predict xb if year==2008
        gen diff=travmale-xb if year==2008
        gen addyear=sum(diff)
        sum addyear

        twoway connected travmale malemortality if age<70 & year==1997, mlabel(age2) ///
        || connected xb malemortality if year==2008 ///
        || connected travmale malemortality if age<70 & year==2008, mlabel(age2) /// ///
        ytitle("Taux d'Emploi") xline(0.497) xline(2.1891) xtitle("Taux de Mortalité (%)") title("Relation emploi/mortalité en Belgique") ///
        legend(position(6) col(2) ///
        order(1 "1997" ///
        2 "linearprediction" ///
        3 "2008"))
        ************************************************** *

        Also, if you don't understand what i'm asking for but still want to give some of your time, i share with you a link "https://www.nber.org/books/wise-22" of a Ebook whith different working papers who are doing what i'm trying to do.
        In all of those papers on working capacity, you can find my issue at the chapters on "Milligan-Wise method"; each autor are doing, on a specific country, what i'm trying to do here. They compute this "vertical difference" in employement for a similar mortality but do not explain how exactly…


        Thank you.

        Attached Files

        Comment


        • #5
          Once more unto the breach.

          Rather than a polynomial try a fitting a line between each point.

          Code:
          levelsof malemortal if year == 1997, local(levels)
          local list ""
          local j = 1
          foreach l of local levels {
              local list `list' v`j' `l'
              local ++j
          }
          mkspline `list'  v21 = malemortality
          reg travmale v1-v20 if year == 1997, nocons
          predict xb if year == 2008
          qui sum malemortality if year == 1997
          replace xb  = . if malemortality < r(min)
          replace xb  = . if malemortality > r(max)
          gen diff=travmale-xb if year==2008
          
          twoway connected travmale malemortality if  year==1997, mlabel(age2)  ///
          || rcapsym  xb travmale malemortality if year==2008 , ms(Oh) ///
          || connected travmale malemortality if year==2008, mlabel(age2)   /// 
          legend(position(6) col(3) ///
          order(1 "1997" ///
          2 "linearprediction" ///
          3 "2008"))

          Comment


          • #6
            Wow Scott,

            I do not understand precisely what do your code but it seems working very well.
            I guess i will have to work on those commands (levelsof , local, mkspline) if i want to master them.

            You helped me a lot here. It was my first post on this forum and thanks to you, surely not the last.

            i hope i did not take to much of your time,
            Thanks a lot,

            PP.

            Comment

            Working...
            X