Announcement

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

  • New to STATA: separating numeric value variable

    Hello,

    I am very new to STATA and am trying to learn by myself. However, I am stuck at this point:

    How can I split a numeric variable 'marstat'. It's label is current marital status - It's components are never married, widowed, etc. and I want to generate a new variable that only consists of 'never married'. Any help or guidance is appreciated.

    Thank you in advance.

  • #2
    Is it a string variable? If so

    Code:
    gen never_married= marstat== "never married"
    If it is a numeric variable and e.g., never married takes on values 2

    Code:
    gen never_married= marstat== 2

    Comment


    • #3
      What is it coded as?
      I am also a learner, but this should work:

      egen varname= anymatch (marstat), value (3)
      tab varname, miss

      where varname is a name you choose for your new variable and 3 must be the numeric value never married is 'tagged' with (ie if never married is coded 1 in your data, you need to change 3 to 1).

      Comment


      • #4
        Thank you so much for your prompt reply!

        I tried both -
        and the second code worked, however, it's giving me 2 values. I only need it to be the '1' with frequency of 169.814. any ideas on how I could do that?

        Click image for larger version

Name:	Screen Shot 2021-05-17 at 02.52.23.png
Views:	1
Size:	28.3 KB
ID:	1610043


        Click image for larger version

Name:	Screen Shot 2021-05-17 at 02.51.26.png
Views:	1
Size:	36.4 KB
ID:	1610044

        Thank you for all your help!

        Comment


        • #5
          EDITED:

          I tried both -
          and the second code worked, however, it's giving me 2 values. I only need it to be the '1' with frequency of 169.814. any ideas on how I could do that?
          You have generated an indicator for never married (=1 if an individual in the sample is never married and zero otherwise). So if you want to run a regression with only the sample of never married individuals, you use the -if- qualifier

          Code:
          regress y x1 x2 ... xN if never_married
          You do not need to drop the other observations. But if you must

          Code:
          drop if !never_married
          tab never_married
          tab marstat
          Last edited by Andrew Musau; 17 May 2021, 04:15.

          Comment


          • #6
            Got it, thank you!

            Comment

            Working...
            X