Reputation: 195
I have a data set similar to this and want to create a count variable under these conditions. If mig
is 1 then count how many of un1
or un2
or un3
are 1 and also count how many of un1
or un2
or un3
in the next time period are 1. So
I want it to be the count of un*
in this period and the next for each individual.
I use the code
egen ... anycount(un1-un3) if mig ==1 & (un1|un2|un3||f.un1|f.un2 |f.un3)
but I cannot get a count of future values.
Id t mig un1 un2 un3 count
1 1 0 0 1 1
1 2 0 0 0 1
1 3 1 0 0 1 4
1 4 0 1 1 1
1 5 0 0 0 0
2 1 0 0 1 0
2 2 1 0 0 0
2 3 0 1 0 0 1
2 4 0 0 0 1
2 5 0 0 0 0
Upvotes: 1
Views: 91
Reputation: 37233
To explain this more fully: You have panel data and have tsset Id t
or similarly using xtset
.
How about
gen count = cond(mig == 1, un1 + un2 + un3 + F.un1 + F.un2 + F.un3, 0)
???
Upvotes: 2