Announcement

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

  • Creating an Attrition Dummy in Panel Data

    Dear all,

    I am working with an unbalanced panel data comprising five waves. I intend to generate a dummy variable identifying individuals (pid) who were observed only in the first two waves (Waves 1 and 2) but not in any subsequent waves (Waves 3, 4, or 5). The dummy variable takes a value of 1 for respondents interviewed in the first two waves who attrited from the panel thereafter, and 0 otherwise.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long pid float wave
    301011 1
    301011 2
    301011 3
    301011 4
    301011 5
    301012 1
    301012 2
    301012 3
    301012 4
    301012 5
    301013 1
    301013 2
    301013 3
    301013 4
    301013 5
    301014 1
    301014 2
    301014 3
    301014 4
    301014 5
    301015 1
    301015 2
    301015 3
    301015 4
    301015 5
    301016 1
    301016 2
    301016 3
    301016 4
    301016 5
    301017 1
    301017 2
    301017 3
    301017 4
    301017 5
    301018 1
    301018 2
    301018 3
    301018 4
    301018 5
    301019 1
    301019 2
    301019 3
    301019 4
    301019 5
    301020 1
    301020 2
    301020 3
    301020 4
    301020 5
    301022 1
    301022 2
    301022 3
    301022 4
    301022 5
    301023 1
    301023 2
    301023 3
    301023 4
    301023 5
    301024 1
    301024 2
    301024 3
    301024 4
    301024 5
    301025 1
    301025 2
    301025 3
    301025 4
    301025 5
    301026 1
    301026 2
    301026 3
    301026 4
    301026 5
    301027 1
    301027 2
    301027 3
    301027 4
    301027 5
    301028 1
    301028 2
    301028 3
    301028 4
    301028 5
    301029 1
    301029 2
    301029 3
    301029 4
    301029 5
    301031 1
    301031 2
    301031 3
    301031 4
    301031 5
    301033 1
    301033 2
    301033 3
    301033 4
    301033 5
    301034 1
    301034 2
    301034 3
    301034 4
    301034 5
    301035 1
    301035 2
    301035 3
    301035 4
    301035 5
    301036 1
    301036 2
    301036 3
    301036 4
    301036 5
    301038 1
    301038 2
    301038 3
    301038 4
    301038 5
    301040 1
    301040 2
    301040 3
    301040 4
    301040 5
    301041 1
    301041 2
    301041 3
    301041 4
    301041 5
    301043 1
    301043 2
    301043 3
    301043 4
    301043 5
    301045 1
    301045 2
    301045 3
    301045 4
    301045 5
    301047 1
    301047 2
    301047 3
    301047 4
    301047 5
    301048 1
    301048 2
    301048 3
    301048 4
    301048 5
    301049 1
    301049 2
    301049 3
    301049 4
    301049 5
    301050 1
    301050 2
    301050 3
    301050 4
    301050 5
    301051 1
    301051 2
    301051 3
    301051 4
    301051 5
    301052 1
    301052 2
    301052 3
    301052 4
    301052 5
    301053 1
    301053 2
    301053 3
    301053 4
    301053 5
    301054 1
    301054 2
    301054 3
    301054 4
    301054 5
    301055 1
    301055 2
    301055 3
    301055 4
    301055 5
    301056 1
    301056 2
    301056 3
    301056 4
    301056 5
    301057 1
    301057 2
    301057 3
    301057 4
    301057 5
    301058 1
    301058 2
    301058 3
    301058 4
    301058 5
    end

  • #2
    Assuming only observed waves are included in the dataset:

    Code:
    bys pid (wave): gen wanted= wave[1]==1 & wave[_N]==2

    Comment


    • #3
      bys pid (wave): gen wanted= wave[1]==1 & wave[_N]==2

      . ta wanted

      wanted | Freq. Percent Cum.
      ------------+-----------------------------------
      0 | 214,835 100.00 100.00
      ------------+-----------------------------------
      Total | 214,835 100.00

      Thanks Andrew Musau , but it doesn't appear to work.

      Comment


      • #4
        Charles:
        if the -pid- does not have observations from wave 3 onwards, it will be simply omitted from the -e(sample)-.
        So why bothering yourself about creating that dummy?
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Charles:
          elaborating a bit on your data excerpt, you may want to consider instead:
          Code:
          bysort pid (wave): drop if _n>2 & pid==301011
          bysort pid (wave): egen check=max( wave) if _n==_N
          list pid check if check!=.
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment


          • #6
            Thanks Carlo Lazzaro. I am trying to estimate the attrition probability for individuals who were successfully interviewed only in waves 1 and 2. Hence the need to create the dummy only for those who were successfully interviewed in the first two waves out of the 5 waves.

            Comment


            • #7
              Originally posted by Charles Ackah View Post
              bys pid (wave): gen wanted= wave[1]==1 & wave[_N]==2

              . ta wanted

              wanted | Freq. Percent Cum.
              ------------+-----------------------------------
              0 | 214,835 100.00 100.00
              ------------+-----------------------------------
              Total | 214,835 100.00

              Thanks Andrew Musau , but it doesn't appear to work.
              As I stated, the code in #2 assumes that only the waves that are present are included in the dataset. If you have the identifier and wave variables present for all waves for each individual, but other variables are missing for unobserved waves, then you will first need to drop the unobserved waves before running #2. As Carlo states, the unobserved waves do not enter the estimation sample, so dropping them does not affect anything. Assuming that your outcome variable is named outcomevar (replace with the name of your outcome variable), you can start by running:
              Code:
              drop if missing(outcomevar)
              followed by #2.

              Comment

              Working...
              X