Announcement

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

  • How can I keep the respondents who responds all the waves?

    id wave question1
    01 7 a
    01 8 a
    01 9 a
    02 7 b
    02 8 a
    03 7 b
    03 8 b
    03 9 c
    04 7 a
    05 7 c
    05 8 b
    wave: 7th~9th only

    I want to keep id number 01 and 03 who responds all in those waves.

    How can I get them?

  • #2
    Guest:
    instead of deleting observation that do not satisfy your conditions, I find better to keep them and separe them from the one you'rer interested in, like in the following toy-example (obviously -wave- is used just to give an example of -sum-):
    Code:
    . bysort id: g flag=1 if (_N-_n)==2
    (9 missing values generated)
    
    . bysort id: replace flag=1 if flag[1]==1
    (4 real changes made)
    
    . sum wave if flag==1
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
            wave |          6           8    .8944272          7          9
    Last edited by sladmin; 30 Nov 2023, 11:58. Reason: anonymize original poster
    Kind regards,
    Carlo
    (StataNow 19.0)

    Comment


    • #3
      Oh, Thank you so much!
      I did it so many times in excel but with a lot of samples, messed up with errors.

      Thanks to your help, I finally get the result by adding simply up the "keep if flag==1")

      Comment


      • #4
        Guest:
        - Stata and spreadsheets are very different; it's recommended to delve into Stata logic and forget the spreadsheet approach altogether when analysing data with Stata;
        - due to some bad experiences in the past, I usually use -if- qualifier to avoid dropping observations. In your codes you should have obtained the same subsample just invoking the condition:
        Code:
        if flag==1
        Last edited by sladmin; 30 Nov 2023, 11:59. Reason: anonymize original poster
        Kind regards,
        Carlo
        (StataNow 19.0)

        Comment


        • #5
          Setting aside what's a good idea (!) you can get there more directly:

          Code:
          clear 
          input str2 id    wave    str1 question1
          01    7    a
          01    8    a
          01    9    a
          02    7    b
          02    8    a
          03    7    b
          03    8    b
          03    9    c
          04    7    a
          05    7    c
          05    8    b
          end 
          
          bysort id : keep if _N == 3 
          
          list, sepby(id) 
          
               +----------------------+
               | id   wave   questi~1 |
               |----------------------|
            1. | 01      7          a |
            2. | 01      8          a |
            3. | 01      9          a |
               |----------------------|
            4. | 03      7          b |
            5. | 03      8          b |
            6. | 03      9          c |
               +----------------------+

          Comment


          • #6
            hi, i know this is an old thread, but it's somewhat in alignment with what I'm trying to do with respondents that answered in all waves. I don't want to drop respondents that didn't answer in all waves, but instead generate a dummy variable to mark those that didn't answer all waves from those that did. Is that possible?

            Comment


            • #7
              Amber:
              you might be interested in something along the following lines:
              Code:
              . set obs 2
              
              . g id=_n
              
              . expand 2
              
              . bysort id: g wave=_n
              
              . g A=runiform()*1000
              
              . replace A = . in 2
              
              . egen flag=rowmiss( A)
              
              . bysort id: egen check=total(flag)
              
              . list
              
                   +-------------------------------------+
                   | id   wave          A   flag   check |
                   |-------------------------------------|
                1. |  1      1   71.10509      0       1 |
                2. |  1      2          .      1       1 |
                3. |  2      1   555.1031      0       0 |
                4. |  2      2    875.991      0       0 |
                   +-------------------------------------+
              Kind regards,
              Carlo
              (StataNow 19.0)

              Comment


              • #8
                #6: In the example of #5 that could be

                Code:
                 
                 bysort id : gen incomplete = _N < 3
                where 3 should be replaced with your own # of waves if different. See also https://www.stata.com/support/faqs/d...rue-and-false/

                Comment


                • #9
                  Hello I am sorry for amending this again, but I have a similar issue.

                  I am using the British Household Survey and have restricted my sample to mothers and have created an indicator variable showing when these mothers switched from employment to maternity leave. I am only interested in studying these mothers across waves.

                  I have tried to only keep those who have experienced this switch but it deletes all of the other wave history of the same mothers apart from the wave at which the switch took place.

                  I basically want to keep the identification number of these mothers but also of the waves each of this id has responded to.

                  There are 700+ of these women so telling stata to keep only these identification numbers would take a lot of time.

                  Also bare in mind that there is no set number of waves that all of the mothers in my list have responded to so I can't just use a certain _N= command given that I don't have such consistency.

                  Below is a table of what my data looks like.

                  id wave employment status
                  1 1 unemployment-->employment
                  1 2 employment--> maternity leave
                  2 6 employment -->employment
                  2 7
                  employment -->employment
                  2 8
                  employment -->employment
                  3 1 employment-->maternity leave
                  3 2 maternity leave-->employment
                  3 4 employment-->employment

                  Thanks in advance

                  Comment


                  • #10
                    #9 is essentially a duplicate post. If interested please follow https://www.statalist.org/forums/for...articular-year

                    Comment

                    Working...
                    X