Announcement

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

  • force cut off point while creating quintiles

    Hello people,

    I am trying to replicate this SAS code in STATA:

    if 0<=literacy<63.82 then litcat1=1;
    if 63.82<=literacy<68.81 then litcat1=2;
    if 68.81<=literacy<73.258 then litcat1=3;
    if 73.258<=literacy<78.829 then litcat1=4;
    if 78.829<=literacy then litcat1=5;

    if litcat1=1 then litcat=1;
    if litcat1 in(2,3,4) then litcat=2;
    if litcat1=5 then litcat=3;

    I have tried the xtile with the if options but STATA says "weights not allowed"
    What should I do?

  • #2
    if is a qualifier, not an option. Your spelling STATA shows that you should please read all the way to https://www.statalist.org/forums/help#spelling

    If you know the breakpoints xtile is irrelevant, indeed useless.

    You could do this:

    Code:
    gen litcat1 = cond(literacy >= 78.829, 5, cond(literacy >= 73.258, 4, cond(literacy >= 68.81, 3, cond(literacy >= 63.82, 2, 1)))) if literacy < .
    or this is a more literal translation of your code

    Code:
    gen litcat1 = 1 if literacy < 63.82
    replace litcat1 = 2 if literacy >= 63.82  & literacy < 68.81
    replace litcat1 = 3 if literacy >= 68.81  & literacy < 73.258
    replace litcat1 = 4 if literacy >= 73.258 & literacy < 78.829
    replace litcat1 = 5 if literacy >= 78.829 & literacy < .
    and similar technique may be used in your second example.

    Note that special care is needed with any missing values.

    The biggest deal is why you feel it necessary to degrade what looks like good data in this way. The arguments in https://bmcmedresmethodol.biomedcent...471-2288-12-21 apply beyond the field of the authors' concern.

    Comment


    • #3
      Thanks Nick.

      I ended up doing this

      gen Literacy_1= 1 if Literacy>0 & Literacy<63.82
      replace Literacy_1= 0 if Literacy_1==.
      gen Literacy_2= 2 if Literacy>63.82 & Literacy<78.82
      replace Literacy_2= 0 if Literacy_2==.
      gen Literacy_3= 3 if Literacy>78.82
      replace Literacy_3= 0 if Literacy_3==.
      gen Literacy_all= Literacy_1+Literacy_2+Literacy_3
      drop Literacy_1 Literacy_2 Literacy_3
      rename Literacy_all litcat

      Comment


      • #4
        What you do here -- not what you ask for in #1 -- can be simplified to one line:

        Code:
        gen litcat = (Literacy>0 & Literacy<=63.82) + 2 * (Literacy>63.82 & Literacy<= 78.82) + 3 * (Literacy>78.82)
        I have corrected some strict inequalities to weak ones, although that probably won't bite you. Any missing values on literacy will get mapped to 3.

        Tertile degradation (I won't dignify it as classification or categorization) is even more of a device for information loss than quintile degradation.

        Comment

        Working...
        X