Dear all,
I have a question about generating a new variable "movingindicator". The dataset variables are id, countycode (=25 means live in Genesee County). How can I generate movingindicator by countycode which,
if she lives in Genesee and then moves out, then generate movingindicator = 1
if she lives out of Genesee County and then moves in, then generate movingindicator = 2
if she lives in Genesee and then moves out and then moves in, then generate movingindicator = 3
if she lives in out of Genesee County and then moves in and then moves out, then generate movingindicator = 3
Please note,
the individual may have a different number of observations,
the individual may have the different number of countycode = 25, for example, id = 1 has 1 row countycode = 25, id =5 has 3 rows countycode = 25, but movingindicator for them are all 1.
Here is the dataset below,
Here is the dataset that I expect,

I spent the whole afternoon working on this, but I didn't solve it. I appreciate if someone can help.
Best regards,
Jack Liang
I have a question about generating a new variable "movingindicator". The dataset variables are id, countycode (=25 means live in Genesee County). How can I generate movingindicator by countycode which,
if she lives in Genesee and then moves out, then generate movingindicator = 1
if she lives out of Genesee County and then moves in, then generate movingindicator = 2
if she lives in Genesee and then moves out and then moves in, then generate movingindicator = 3
if she lives in out of Genesee County and then moves in and then moves out, then generate movingindicator = 3
Please note,
the individual may have a different number of observations,
the individual may have the different number of countycode = 25, for example, id = 1 has 1 row countycode = 25, id =5 has 3 rows countycode = 25, but movingindicator for them are all 1.
Here is the dataset below,
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id countycode) 1 25 1 26 1 98 2 69 2 72 2 88 2 25 2 25 2 25 3 25 3 29 3 25 3 40 4 60 4 25 4 49 5 25 5 25 5 25 5 4 6 49 6 82 6 25 end
I spent the whole afternoon working on this, but I didn't solve it. I appreciate if someone can help.
Best regards,
Jack Liang
Comment