Announcement

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

  • Generating new variables based on criateria

    Hi,

    I want to generate a new variable based on criteria.

    I have the data for, let's say, 20 different regions and each region has a percentage of child, young and old persons (which equals to 100%).
    It looks like this:
    Regions--child-- young--old
    region 1--25--20--55
    region 2--50--50--00
    .
    .
    .
    region 20-- 75--20--5

    Now I want to divide regions into 3 different categories, i.e., regions with a majority of children, regions with a majority of young ones, and regions with a majority of old ones.
    Here each category would be represented by a dummy (0.1).

    Could you please tell me, how can I do this in stata?

  • #2
    Since the post did not follow the FAQ (http://www.statalist.org/forums/help) and use -dataex-, I've converted the data into code form for those who would like to help:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(region child young old)
     1 25 20 55
     2 50 50  0
    20 75 20  5
    end
    Also, "majority" is a vague term. It may be helpful to define what is the threshold, and how would you like to resolve ties observed in region 2.

    Comment


    • #3
      In a situation like region 2, which is 50% child and 50% young, is this majority children, majority young, or not majority-anything?

      Added: Crossed with #2 which raises the same question.

      Comment


      • #4
        Ken Chui thank you very much.

        Comment


        • #5
          Clyde Schechter thank you very much for your response.

          Okay, let's call that case as "not majority-anything". However, these type of cases are rare in the dataset.

          Comment


          • #6
            By majority I mean, the highest number of individuals.

            Comment


            • #7
              Code:
              foreach v of varlist child_young_old {
                  gen byte majority_`v' = (`v' > 50) & !missing(`v')
              }

              Comment

              Working...
              X