Announcement

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

  • Drawing a line through the outer XY combinations below the trend line

    The eventual goal is to assign minimum value of actl for a new exp value (where actl is missing). I think I should first come over the issue of drawing a line passing through these observations to use for a decision rule, but not really sure how to attack this problem.
    Thank you in advance

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(actl exp) byte minactl
     .  .4306503 .
    .6 .43129745 .
    .4  .4318457 .
    .4   .432377 .
    .4  .4326184 .
    .4  .4332968 .
    .3  .4353066 .
    .3  .4364009 .
    .4  .4389387 .
     .  .4391871 .
     .  .4402585 .
    .4  .4403833 .
     . .44135585 .
     .  .4416456 .
     .  .4417434 .
     .  .4419167 .
     .  .4438399 .
    .4  .4453161 .
     .  .4481203 .
     .  .4515771 .
    .4  .4517835 .
     .  .4522247 .
    .4  .4527117 .
    .3  .4529815 .
    .3  .4544157 .
    .5  .4677871 .
    .4  .4767839 .
    .6  .4869735 .
    .6  .4926984 .
    .4 .51891696 .
    .3 .52825445 .
    .4 .53248686 .
    .4  .5328437 .
     .  .5332037 .
    .6  .5334881 .
    .6  .5335155 .
    .5  .5338645 .
    .5 .53483564 .
    .6 .53746325 .
    .5  .5404169 .
     .  .5407301 .
     . .54236794 .
    .4  .5438738 .
    .5  .5484574 .
    .5 .55163646 .
    .4 .55418557 .
     .  .5592771 .
     . .56299645 .
    .8  .5669411 .
     .  .5672508 .
     .  .5673133 .
     . .56743836 .
     . .56973493 .
     .  .5727739 .
    .8 .57350165 .
    .6 .57357556 .
     .   .573942 .
     .  .5740153 .
     . .57531005 .
     .  .5799186 .
    .6  .5843775 .
    .5 .58538944 .
    .6 .58968616 .
    .5 .59198374 .
     . .59305274 .
    .4  .5949966 .
    .4  .5956155 .
    .7  .5968927 .
    .8  .5977873 .
    .7  .5997788 .
     .  .6584147 .
     1  .6827189 .
     1  .6881836 .
     .  .6882014 .
     .  .6898127 .
     1  .6934553 .
     .  .7054474 .
    .7   .707083 .
     .  .7075651 .
     .  .7090087 .
    .9  .7098652 .
     .  .7100893 .
     .  .7105488 .
     .  .7108207 .
     .  .7110068 .
     .  .7116353 .
     .  .7138406 .
    .6  .7139603 .
     .  .7140106 .
     .    .71864 .
     .  .7186521 .
    .4  .7188953 .
    .5  .7188953 .
     .  .7204999 .
    .7   .720687 .
     .  .7210785 .
     .  .7215325 .
    .7  .7218328 .
     .  .7218585 .
     .   .728121 .
    end
    enter
    scatter actl exp

    to see the scatter plot. Visually I am trying to get a line passing through the lowest XY points to assign the minimum value of Actl to a new Exp var that does not have a known Actl value yet.
    Actl is always discrete between 0 and 1 in multiples of 0.1 and Exp is continuous between 0-1 domain.

    Last edited by Oscar Ozfidan; 01 Mar 2019, 12:28.

  • #2
    I am not sure I follow exactly what you are after but here is one attempt:

    Code:
    qui sum act
    local miny = r(min)
    replace act = r(min) if missing(act)
    qui sum exp
    local minx = r(min)
    scatter ac exp, xline(`minx') yline(`miny')

    Comment


    • #3
      Scott
      Thanks for the attempt.
      I was able to pick out the XY coordinates of most where the (stepwise) line would go through once I do it right.
      I used the following code. However, Maxexp[2] should still be replaced by Maxexp[4] to get the right XY coordinate and Maxexp[7] should be Maxexp[8]. Then the remaining points will accurately delineate what the minimum actl that should be assigned for a new value of exp. The problem is I need to automate this procedure because I will have the same issue for many more combinations of XY data with different variables.



      gen Maxexp =.
      foreach j of numlist 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1 {

      summarize exp if actl == float(`j')
      replace Maxexp = r(max) if actl == float(`j')

      }

      sort actl
      replace Maxexp =. if actl[_n] <= actl[_n-1] & _n != 1

      sort Maxexp

      scatter actl Maxexp

      Comment


      • #4
        Solved! For reference, following code does the trick.

        gen Maxexp = exp
        gen Minactltmp = actl
        foreach j of numlist 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1 {

        qui sum exp if actl == float(`j')
        replace Maxexp = r(max) if actl == float(`j')

        }

        sort actl
        replace Maxexp =. if actl[_n] <= actl[_n-1] & _n != 1

        replace Minactltmp =. if Maxexp ==.
        sort Minactltmp
        replace Maxexp = Maxexp[_n-1] if Minactltmp[_n] > Minactltmp[_n-1] & _n != 1 & Maxexp[_n] < Maxexp[_n-1]

        gen Minactlexp = cond(exp<=Maxexp[1],Minactltmp[1], cond(exp>Maxexp[1] & exp<=Maxexp[2],Minactltmp[2],cond(exp>Maxexp[2] & exp<=Maxexp[3],Minactltmp[3],cond(exp>Maxexp[3] & exp<=Maxexp[4],Minactltmp[4],cond(exp>Maxexp[4] & exp<=Maxexp[5],Minactltmp[5],cond(exp>Maxexp[5] & exp<=Maxexp[6],Minactltmp[6], ///
        cond(exp>Maxexp[6] & exp<=Maxexp[7],Minactltmp[7],cond(exp>Maxexp[7] & exp<=Maxexp[8],Minactltmp[8],cond(exp>Maxexp[8] & exp<=Maxexp[9],Minactltmp[9],cond(exp>Maxexp[9] & exp<=Maxexp[10],Minactltmp[10],cond(exp>Maxexp[10] & exp<=Maxexp[11],Minactltmp[11],.)))))))))))

        drop Maxexp Minactltmp

        scatter actl Minactlexp exp

        Comment

        Working...
        X