Announcement

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

  • Panel data- Difficulty removing individuals that perform an action multiple times

    Hello all,

    I have used -tabstat- to identify if an individual had performed a certain action multiple times. If the result is 1, I would would like to keep the data from the person; if the person has more that 1, I would like to remove them from the data set. Is there way do this or would I have to do this manually?

    I am using stata 15.0 for Windows.

    For extra information, I am using panel data to see the effects that the act of internal migration has on a person's subjective well being. I was having trouble with individuals that moved multiple times so I decided to look at individuals that moved either once or not all.

    I used
    tabstat M0,statistic( sum )by(pid)
    to find out how many times an individual moved.

    To clarify variables: pid = person identification, movest = mover status, M0 = if they moved ( I created M0 by)
    gen M0 = (movest==2)


    This is an example of my data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long pid byte movest float M0
    10007857 4 0
    10007857 1 0
    10007857 1 0
    10007857 1 0
    10014578 1 0
    10014578 1 0
    10014578 1 0
    10014578 1 0
    10014578 1 0
    10014578 1 0
    10014578 1 0
    10014578 1 0
    10014578 1 0
    10014578 2 1
    10014578 1 0
    10014608 1 0
    10014608 1 0
    10014608 1 0
    10014608 1 0
    10014608 1 0
    10014608 1 0
    10014608 1 0
    10014608 1 0
    10014608 1 0
    10014608 2 1
    10014608 1 0
    10016813 1 0
    10016813 1 0
    10016813 1 0
    10016813 1 0
    10016813 1 0
    10016813 1 0
    10016848 2 1
    10016848 1 0
    10016848 1 0
    10016848 1 0
    10016848 1 0
    10016848 1 0
    10016848 1 0
    10016848 1 0
    10016848 1 0
    10016848 1 0
    10016848 1 0
    10016848 1 0
    10016872 1 0
    10016872 1 0
    10016872 1 0
    10016872 1 0
    10016872 1 0
    10016872 1 0
    10016872 1 0
    10016872 1 0
    10016872 1 0
    10016872 1 0
    10016872 2 1
    10017933 1 0
    10017933 1 0
    10017933 1 0
    10017933 1 0
    10017933 1 0
    10017933 1 0
    10017933 1 0
    10017933 1 0
    10017933 1 0
    10017933 1 0
    10017933 1 0
    10017933 1 0
    10017933 1 0
    10017992 1 0
    10017992 1 0
    10017992 1 0
    10017992 1 0
    10017992 1 0
    10017992 1 0
    10017992 1 0
    10017992 1 0
    10017992 1 0
    10017992 1 0
    10017992 1 0
    10017992 1 0
    10019057 2 1
    10019057 1 0
    10019057 1 0
    10019057 1 0
    10019057 1 0
    10019057 1 0
    10019057 1 0
    10019057 1 0
    10019057 1 0
    10019057 1 0
    10019057 1 0
    10019057 1 0
    10019057 1 0
    10023526 1 0
    10023526 1 0
    10023526 1 0
    10023526 1 0
    10023526 1 0
    10023526 1 0
    10023526 1 0
    end
    label values movest fmovest
    label def fmovest 1 "non-mover", modify
    label def fmovest 2 "mover within gb", modify
    label def fmovest 4 "mover back to gb", modify
    Thank you for the help.


  • #2
    So, you want to know if a single person has moved within Great Britain more than once? You've marked the people that move within GB by a '1' in M0?

    In that case, you can sum the total of M0 per person. If it exceeds 1, that means he has moved more than once and we drop that person from the dataset.

    Code:
    bysort pid: egen total_moves = total(M0)
    drop if total_moves > 1
    drop total_moves

    Comment


    • #3
      Thank you very much.

      Comment

      Working...
      X