Announcement

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

  • How to get Stata to return where two variables intersect for the second time

    Hello everyone,

    I am modelling optimal marginal income tax rates. I use two models. One is very volatile for extremely high incomes, which is why I use a second model which works only for very high incomes. To compute my final marginal tax rates, I need to merge the results of the two models based on where they intersect for high incomes. I know this is always the second time they intersect. The image below shows an example of the situation:
    Click image for larger version

Name:	example.png
Views:	1
Size:	34.3 KB
ID:	1553637


    Variables are mtr and mtrh

    Essentially, I want Stata to find where the two variables intersect for the second time. Then, have Stata generate a new variable which equals mtr for all levels of income below the intersection, and the then equal the rate of the intersection (constant) for the high levels of income.
    I could easily do this manually, but since I want to simulate this endless times using different income distributions, I would much rather have Stata do it for me.
    If I could get Stata to return the level of income for which mtr and mtrh intersect for the second time, I would be able to generate the desired variable easily. Can anyone help me with this?

    Kind regards,

    Patrick Lambertus

  • #2
    Sure, dataex you example here.
    Also clarify of (0,0) is considered to be the first intersection or not.

    Comment


    • #3
      Thanks for your reply.

      Sorry, (0,0) is technically the first intersection. This means that I am looking for the third intersection, in this case around the income of 200,000.

      These plots are based on 10,000 observations, so I think dataex would not be that useful in this case. Even with a random sample of 500 the plot might be very inaccurate since there are relatively few observations for high incomes.

      Also, the data are sorted by income. This means that all I need is a way to identify the third intersection of mtr and mtrh over income (or over _n).

      Code below shows what I have done for now. Note that var z is income, and newvar mtrf is the final marginal tax rate. My best estimation is that the intersection I am looking for always happens after the 95th percentile, and I currently use 10,000 obs, hence the use of z>z[9500]. Var seqnum is _n, and the dataset is sorted by z.

      Code:
      gen mtrf = mtrh if mtrh<mtr & z>z[9500]
      label variable mtrf "Final marginal tax rate"
      sum seqnum if !missing(mtrf)
      replace mtrf = mtrf[r(min)] if _n >r(min)
      replace mtrf = mtr if missing(mtrf)
      This works for now, but it relies on z[9500] being between the second and third intersection. I will still need to manually confirm that this is the case if I want to use this code. Hence, a more reliable method to find the third intersection is still desired.

      Comment


      • #4
        Code:
        tempvar o z zo
        generate byte `o'=y1>y2
        generate byte `z'=`o'!=`o'[_n-1]
        generate int `zo'=`z' in 1
        replace `zo'=`zo'[_n-1]+`z' in 2/L
        summarize t if `z'==1 & `zo'==3
        local tstar=r(min)
        summarize y1 if `z'==1 & `zo'==3
        local ystar=r(min)
        Click image for larger version

Name:	intersection.png
Views:	1
Size:	81.2 KB
ID:	1553821

        Comment


        • #5
          Thank you very much Sergiy! Using the code you provided, I am able to compute the rates exactly as I want, relying completely on the third intersection of the two variables.

          Comment

          Working...
          X