Announcement

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

  • Help with generate ratio variable

    Hi everyone,

    I want to make a new variable (Gender Diversity Ratio). I already have a variable that has the proportion female on total (so: GDR1 = female/total). I want to remake the variable so that GDR2 = 1 when GDR1 = 0.5 (=100% diversity, because 50 male:50 female).
    And for example when GDR1 = 0.8 or GDR1= 0.4 than the 0.4 will closer to GDR2 = 1 than the 0.8, because GDR1 of 40% means 40% females and 60% males which is more diverse than 80% female and 20% male.
    GDR2 can not provide whether more females or more males is "better" on my dependent variable, but only whether diversity is better/worse.

    Which commands do I need to use? I added a imaginary dataset in the table below, where the blank cells need to be get a value.
    GDR1 GDR2
    0.2
    0.5 1
    0.6
    0.7

    Thanks in advance!
    Josephine




  • #2
    maybe,
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float grd
      0
    .05
     .1
    .15
     .2
    .25
     .3
    .35
     .4
    .45
     .5
    .55
     .6
    .65
     .7
    .75
     .8
    .85
     .9
    .95
      1
    end
    gen wanted = inrange(grd, .25, .75)

    Comment


    • #3
      Josephine:
      I'm not familiar wity this kind of data. So please consider my reply as tentative.
      Code:
      . replace gdr2=gdr1/.5 if gdr1<=.5
      
      . replace gdr2=(gdr1-.5)/.5 if gdr1>.5
      
      
      . list
      
           +-------------+
           | gdr1   gdr2 |
           |-------------|
        1. |   .2     .4 |
        2. |   .5      1 |
        3. |   .6     .2 |
        4. |   .7     .4 |
           +-------------+
      
      .
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment

      Working...
      X