Announcement

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

  • Variable Construction

    Hi all

    I have to construct the following variable please I am not sure please how to write this formula in stata please help to do this

    Son Preference Ratio, is the degree of son preference measured by the ratio of the desired number of sons to the desired number of daughters above the natural rate of one.

    The formula is attached in the picture please


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(sons girls)
     5  5
     4  4
     2  2
     2  2
     2  1
    10 10
    96 96
     2  2
     5  5
     2  2
     2  5
     2  3
     3  3
     2  3
     2  1
     1  2
     2  0
     3  2
     4  4
     2  2
     3  2
     0  3
     2  2
     3  3
     2  2
     2  2
     1  1
     3  2
     4  3
     2  2
     2  2
     2  2
     4  4
     2  3
     0  0
     3  3
     1  1
     1  2
     2  1
     1  2
     2  3
     2  2
     2  2
     2  2
     2  3
     0  0
     0  0
     1  1
     5  5
     2  2
     1  1
     2  2
     3  3
     1  1
     1  1
     1  1
     2  2
     3  4
     2  2
     1  3
     3  2
     2  1
     2  2
     3  4
     1  1
     4  3
     2  2
     1  3
     0  1
     1  1
     2  2
     2  2
     0  0
     0  0
     1  2
     3  4
    96 96
     1  1
     2  2
     1  1
     1  1
     0  0
     2  2
     1  1
     2  1
     0  0
     1  2
     2  1
     0  0
     2  2
     1  1
     1  1
     2  2
     0  0
     2  2
     0  0
     2  3
     5  4
     3  2
     4  3
     3  3
     2  1
     2  2
     2  2
     0  0
     2  2
     0  0
     2  1
     0  0
     2  1
     2  3
     2  3
     2  2
     0  0
    96 96
     2  2
     2  1
     1  2
     2  2
     3  3
     1  1
     2  1
     1  1
     2  2
     2  2
     1  1
     1  2
     2  1
     1  2
     1  1
     2  4
     2  2
     2  2
     2  1
     4  2
     1  1
     1  1
     2  2
     1  1
     3  3
     3  2
     2  2
     2  2
     1  1
     2  4
     1  2
     2  2
     1  1
     2  3
     2  2
     2  2
     1  1
     4  4
     2  1
     3  3
     2  2
     2  3
     1  1
     2  1
     2  2
     0  0
     2  3
     2  2
     3  3
     0  0
     2  2
     0  0
     0  0
     1  2
     1  2
     1  1
     1  1
     1  2
     2  3
     3  4
     2  6
     1  4
     2  2
     1  1
     1  1
     3  4
     1  1
     1  1
     1  1
     4  2
     3  2
     1  3
     2  1
     2  2
     2  4
     1  1
     2  2
     1  1
     3  3
     3  2
     2  2
     2  2
     4  3
     4  2
     2  2
     3  3
     4  2
     6  6
     1  1
     3  2
     2  2
     2  2
     3  2
     2  2
     2  5
     2  2
     2  2
     2  2
     3  3
     0  0
     3  4
     4  4
     2  3
     0  0
     2  2
     2  2
     2  3
     1  2
     2  3
     2  2
     4  3
     1  1
     1  0
     1  2
     2  2
     1  1
     3  1
     2  2
     2  4
     2  2
     3  2
     4  3
     2  5
     3  2
     2  2
     2  2
     0  0
     1  1
     0  0
     4  4
     2  2
     4  4
     5  5
     1  1
     3  2
     2  3
     2  2
     1  1
    96 96
     0  0
     2  1
     2  2
     2  2
     1  1
     1  2
     1  2
     0  1
     0  0
     1  1
     0  0
     0  0
     1  1
     0  0
     2  3
     2  2
     2  2
     2  1
     2  2
     1  2
     1  1
     2  2
     1  1
     1  2
     1  1
     0  0
     0  0
     1  1
     0  0
     2  1
     1  0
     0  0
     0  2
     2  2
     0  0
     0  0
     2  2
     0  0
     2  1
     1  1
     0  0
     0  0
     2  2
     2  1
     1  2
     1  1
     2  2
     1  1
     0  0
     0  0
     1  1
     2  2
     0  0
     0  0
     2  3
     2  2
     1  1
     2  2
     2  2
     1  1
     2  3
     3  2
     3  3
     3  3
     0  0
     2  1
     3  3
     0  0
     2  2
     2  3
     5  5
     2  1
     5  5
     2  2
     3  3
     2  2
     0  0
     2  1
     1  1
     0  0
     1  1
     2  1
     2  3
     3  2
     1  1
     3  3
     2  3
     2  1
     3  3
     2  3
     1  1
     2  2
     2  2
     2  2
     5  5
     3  2
     1  1
     0  0
     3  3
     2  2
    96 96
     2  2
     3  6
     2  2
     3  2
     3  3
     2  2
     4  4
     4  4
     1  2
     2  0
     2  2
     1  2
     0  0
     5  5
     2  1
     4  4
     1  1
     1  1
     2  3
     4  4
     3  3
     2  2
     2  2
     2  3
     2  1
     3  2
     1  1
     6  6
     3  2
     2  2
     1  1
     3  3
     2  2
     1  1
     1  2
     1  1
     4  3
     1  1
     3  3
     1  1
     2  2
     1  1
     1  2
     2  2
     2  2
     0  0
     1  1
     2  1
     1  1
     1  2
     1  1
     0  0
     2  3
     1  1
     2  2
     1  1
     2  2
     2  2
     0  0
     1  1
     1  0
     3  3
     1  1
     2  2
     1  1
     2  1
     2  1
     2  1
     3  3
     0  1
     1  2
     2  2
     4  3
     2  2
     3  3
     0  0
     3  2
     1  2
     3  3
     0  0
     2  2
     2  2
     2  2
     1  2
     3  2
     2  2
     1  1
     2  2
     3  3
     0  0
     1  1
     0  0
     0  0
     0  0
     0  0
     0  0
     0  0
     0  0
     2  2
     0  0
     0  0
     0  0
     0  0
     0  0
     2  2
     0  0
     0  0
     0  0
     2  3
     0  0
     0  0
     0  0
     3  3
     2  2
     2  2
     3  5
     3  1
     2  3
     3  3
    96 96
     1  2
     4  2
     1  1
     5  5
     0  0
     2  3
     3  3
     2  2
     2  2
     1  1
     2  2
     3  2
     1  1
     2  2
     2  2
     2  3
     3  2
     2  3
     3  2
     1  1
     2  2
     0  5
     3  4
     2  1
     2  2
     0  0
     3  3
     1  2
     1  1
     2  4
     0  0
     0  0
     2  2
     1  1
     2  2
     0  0
     1  1
     1  1
     2  2
     2  2
     3  1
     3  3
     2  2
     2  1
     0  0
     1  1
     0  1
     2  2
     1  1
     6  0
     1  1
     0  2
     1  2
     2  4
     2  0
     2  2
     1  1
     2  2
     2  2
     1  1
     0  0
     1  1
     0  0
     1  1
     1  1
     2  2
     3  2
     2  2
     2  3
     2  3
     3  3
     0  1
     2  2
     2  2
     2  3
     2  2
     5  5
     1  1
     2  2
     1  3
     1  2
     2  3
     2  2
     2  3
     2  2
     2  2
     2  2
     2  1
     2  2
     2  2
     3  2
     1  1
     2  3
     1  1
     3  2
     1  1
     0  0
     1  1
     2  2
     2  2
     1  1
     0  0
     0  0
     2  1
     2  3
     2  2
     3  3
     3  2
     4  4
     2  2
     2  2
     3  3
     3  3
     3  3
     2  2
     2  2
     1  1
     2  2
     2  1
    96 96
     2  2
     1  2
     2  2
     1  2
     2  2
     1  2
     1  1
     2  1
     0  0
     0  0
     1  1
     1  1
     1  1
     1  1
     1  1
     1  1
     2  1
     2  1
     2  0
     2  2
     2  2
     3  2
     2  2
     3  3
     2  2
     1  0
     0  0
     2  1
     0  3
     1  1
     1  1
     4  1
     1  1
     1  1
     2  2
     0  0
     1  1
     2  2
     2  2
     2  2
     2  2
     2  2
     2  2
     2  2
     2  2
     2  2
     2  3
     2  0
     1  1
     1  1
     1  1
     1  1
     1  1
     1  1
     0  2
     1  1
     1  1
     1  4
     1  2
     4  4
     0  0
     0  4
     5  3
     0  2
     1  1
     2  2
     1  2
     3  3
     1  1
     2  2
     3  3
     5  5
     2  2
     2  2
     1  2
     1  3
     1  3
     0  2
     1  1
     2  3
     2  2
     3  3
     2  2
     1  2
     3  3
     1  1
     2  2
     2  1
     1  2
     2  0
     2  2
     0  0
     2  2
     0  0
     1  1
     0  0
     0  0
     0  0
     1  2
     3  1
     1  2
     0  0
     2  2
     2  2
     1  1
     1  1
     0  0
     1  1
     2  1
     2  3
     1  1
     2  2
     0  0
     1  1
     2  2
     0  0
     2  0
     1  2
     2  1
     3  0
     0  0
     2  2
     2  1
     1  1
     1  2
     1  1
     1  1
     0  0
     0  0
     2  1
     1  2
     2  2
     0  0
     0  0
     2  2
     2  2
     0  0
     2  2
     1  2
     2  2
     2  2
     0  0
     0  2
     1  1
     2  2
     2  2
     1  1
    96 96
     1  1
     5  2
     2  3
     0  0
     1  1
     2  2
     1  1
     2  2
     1  1
     1  2
     2  2
     1  1
     2  1
     4  5
     2  1
     1  1
    96 96
     2  2
     2  2
     1  0
     1  2
     2  1
     0  0
     2  2
     2  2
     1  2
     1  1
     1  1
    10 10
     1  1
     2  3
     2  2
     3  2
     2  2
     2  3
     1  1
     0  0
     0  0
     0  0
     3  3
     2  1
     2  2
     2  1
     2  1
     4  4
     3  2
     2  1
     2  3
     0  0
     3  2
    96 96
     2  2
     1  1
     1  1
     1  1
     1  1
     1  1
     1  2
     1  2
     1  1
     2  2
     0  0
     2  1
     5  0
     1  1
     0  3
     0  0
     2  2
     2  3
     1  3
     3  0
     2  3
     2  2
     3  2
     2  3
     2  2
     1  2
     1  1
     2  1
     0  4
     1  1
     0  0
     4  3
     2  3
     2  3
     1  1
     3  2
     2  3
     1  2
     2  2
     1  3
     0  0
     2  2
     0  0
     1  2
     3  3
     2  1
     1  2
     2  2
     1  2
     1  2
     1  2
     1  2
     0  0
     1  2
     2  2
     3  2
     4  3
     2  3
     3  2
     2  2
     3  3
     3  3
     2  1
     4  3
     2  2
     3  3
     2  2
     0  0
     2  2
     2  2
     4  5
     2  3
     2  3
     1  2
     2  2
     0  2
     2  2
     2  2
     3  2
     3  2
     1  1
     2  1
     2  2
     0  0
     1  1
     2  2
     2  2
     1  1
     2  2
     2  2
     2  1
     1  1
     1  1
     1  1
     1  2
     1  1
     2  0
     2  3
     1  1
     2  3
     2  1
     1  1
     1  2
     2  2
     1  1
     1  1
     0  0
     3  2
     3  1
     2  2
     1  1
     1  1
     2  2
     2  3
     2  2
     3  3
     2  1
     3  2
     1  1
     1  1
     2  2
     1  1
     4  4
     3  3
     1  1
     3  4
     0  1
     1  1
     2  1
     2  2
     3  2
     2  2
     2  1
    96 96
     2  2
     0  0
     3  3
     2  2
     2  3
     2  2
     3  3
     6  4
     1  1
     0  0
     3  2
     2  2
     1  2
     2  4
     2  2
     3  3
     2  3
     2  1
     2  2
     3  4
     1  1
     1  1
     0  0
     1  3
     1  1
     2  2
     1  1
     2  1
     0  2
     2  2
     1  1
     0  0
     2  1
     0  0
     0  0
     2  2
     0  0
     0  0
     0  0
     1  1
     1  1
     1  2
     1  3
     4  5
     2  2
     1  2
     2  2
     3  2
     2  3
     3  2
     2  2
     1  4
     3  3
     1  1
     1  2
     0  0
     2  2
     2  2
     3  2
     2  6
     1  1
     2  1
     4  2
     2  3
     2  1
     2  2
    10  5
     2  2
     2  3
     1  1
     5  5
     1  1
    end
    label values sons V627
    label def V627 96 "other", modify
    label values girls V628
    label def V628 96 "other", modify
    Attached Files

  • #2
    Code:
    gen son_preference_ratio = max(0, sons/girls - 1)
    BUT, what on earth are all those 96's in your data? That number of children could only be achieved by a man through industrial-scale polygyny or rampant rape. And for a woman it would be altogether impossible.

    Comment


    • #3
      gen Son_Preference_Ratio1 = max(0, sons/girls) - 1

      gen Son_Preference_Ratio = max(0, (sons/girls - 1))


      which of these is correct please

      Comment


      • #4
        Originally posted by Clyde Schechter View Post
        Code:
        gen son_preference_ratio = max(0, sons/girls - 1)
        BUT, what on earth are all those 96's in your data? That number of children could only be achieved by a man through industrial-scale polygyny or rampant rape. And for a woman it would be altogether impossible.
        Thanks

        96 represents the missing data.

        and Do I have to replace the 96 with "." or 0 please

        Comment


        • #5
          You have to replace 96 with ".".

          Comment


          • #6
            Thanks

            why not write the formula like this please

            gen Son_Preference_Ratio1 = max(0, sons/girls) - 1

            Comment


            • #7
              That would give different, incorrect results if a respondent prefers more girls than boys. Suppose some respondent wants 5 girls and 3 boys. The code in #2 calculates the son_preference_ratio as max(0, 3/5-1) = max(0, -2/5) = 0, which is what the mathematical formula you showed in #1 would give. But the formula in #6 gives max(0, 3/5)-1 = 3/5 - 1 = -2/5.

              Notice something else. If the formula really were max(0, sons/girls) -1, it could be further simplified to just sons/girls-1 because both sons and girls are at least 0, so sons/girls will never be less than 0 and the entire max(0,....) part of the formula is pointless. Whenever you see a construction like max(0, something), the whole point of that is that if something can be negative we don't want to go there--0 is the lowest value we want.

              Comment


              • #8
                Thanks Clyde Schechter

                Comment

                Working...
                X