Announcement

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

  • Calculating variable "sex" from personal-id-number.

    Dear forum members!

    Me and my fellow student have just recently ventured into our first encounter with Stata. We are medicine students and currently writing our theseis. We are planning to use Stata as tool to analyze a dataset registered by our university hospital. We've never used stata before, nor has our uni. given any introduction - so please exuse us if our question is trivial or found easily elsewhere.

    We need to create a variabel with "sex". To our understanding, the only way for us to do this is to use the personal id-numbers in our datatset, (as the last digit, even vs. odd indicates whether the subject is male or female). Is there a way for Stata to calculate this into a new variable??

    Thanks in advance for any help that can help us solve this issue!

    Regards
    Mikael and Henrik


  • #2
    http://www.stata.com/statalist/archi.../msg01068.html

    Comment


    • #3
      Welcome to Statalist!

      Despite the lack of instruction from your university, you're not totally at a loss for Stata instruction, because the manuals included with Stata (and installed as PDF files accessible from the PDF Documentation item on Stata's Help menu) provide a wealth of information, and a good part of it is aimed at familiarizing new users of Stata with its use.

      When I began using Stata in a serious way last fall, I started by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. Actually, I also read the Stata User's Guide from beginning to end, as is recommended for new users.

      The link referred to in post #2 presupposes that your ID numbers are stored as a numeric data type, rather than as a string that may have non-digit characters as part of it. You will in general get better advice from the members of Statalist if you are more forthcoming about the details of your data. If you haven't already done so, you should review the Statalist FAQ linked to from the top of the page, especially sections 9-12 on how to best pose your question. The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

      Comment


      • #4
        Andrew's reference is certainly pertinent and William gives good advice as always.

        If your ID numbers are strings, then it is something like

        Code:
         
        gen female = inlist(substr(PNR, -1, 1), "1", "3", "5", "7", "9")
        It's good practice to name an indicator variable by whichever state counts as positive, here being female. The last digit is odd when the last character is one of those mentioned and even otherwise, and the numeric result will be 1 or 0 accordingly.

        Comment

        Working...
        X