Announcement

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

  • How to separate data from one variable into two, without missing in STATA?

    I have a dataset with answers form 2004 and 2016 in the same variable, but I want to separate the answers by year without missing values in my two new variables
    … Read more
    Dataset

  • #2
    Hi Emma
    Whatever you were trying to do, is not properly linked.
    So why don't you explain what is the problem you are facing. so one may provide you with some advice.
    Fernando

    Comment


    • #3
      Hey again Fernando

      I simply want to separate my gender variable into two different ones for each year like this (see picture)

      But if I use the separate command it codes the other year into missing values (see picture two)

      Is it possible to run the separate command, where it creates two sets of variables without including the opposite year in each variable as missing values?

      I hope this explains my problem


      Attached Files

      Comment


      • #4
        I think i understand the problem. The solution, however depends on what is what you want to do.
        RIght now your data set organized as follows:
        Code:
        gender   year  
        1         1
        2         1
        1         2
        2         2
        Using separate, this is what you get:
        Code:
        gender   year  gender1   gender2
        1         1      1         .
        2         1      2         .
        1         2      .         1
        2         2      .         2
        So you could replace the missing values with anything else, doing something like:
        Code:
        recode gender1 gender2 (.=0)
        But something tells me that isn't what you want. what else can you tell us about the task you are trying to do?
        Fernando

        Comment


        • #5
          Thank you for your help. It wasn't quite what I'm looking for.

          I have a cumulative dataset, and wish to separate the observations from 2004 and 2016 independently (hence separate the two). When I do the separate commando on one year, the opposite year's observations are coded to missing value, involuntarily on my part. How do one keep the observations from 2004 and 2016, when separating the two?

          Example:
          We wish to keep the observations on the gender variable on two different years.
          CURRENT VARIABLE NEW VARIABLE 2004 NEW VARIABLE 2016
          2004 MALE 2004 MALE 2016 FEMALE
          2004 MALE 2004 FEMALE 2016 FEMALE
          2004 FEMALE 2004 FEMALE 2016 MALE
          2004 MALE 2004 MALE 2016 MALE
          2016 MALE 2004 MALE 2016 MALE
          2016 FEMALE 2004 MALE 2016 MALE
          2016 MALE 2004 MALE 2016 FEMALE

          I wish to keep both observations in 2004 and 2016, as illustrated in the table above. I hope this explains it further.

          Thanks in advance!

          Comment


          • #6
            the problem is not very clear yet.
            How do you know that observation 1 will have the value 2016female or observation 5 will have 2004male?

            Comment


            • #7
              Hi again Fernando

              I have attached a picture of the browse window of my separated variables.

              I only want the Gender2004 variable to include observations for 2004 and not code the 2016 observations into missing values
              Likewise for Gender2016 variable, only to include the data for 2016 and not code the 2004 observations into missing values

              Any idea how I separate Gender into the two variables (Gender2004, Gender2016) without getting the missing values for the opposite year included in the new variables?

              My commands have been:
              keep Gender Year_Of_Study
              keep if Gender == 2004 | Gender == 2016
              separate Gender, by(Year_Of_Study) // generates the two new variables (Gender2004, Gender2016)

              Thank you very much for helping me out!
              Attached Files

              Comment

              Working...
              X