Hi,
I am trying to randomly select an individual using the household id. Households have been interviewed in different rounds. Some have been interviewed in all four rounds while some have been interviewed in only 1 or 2 or 3. Based on this information, I am trying to do the following:
Randomly selecting a person from every household that has been interviewed four times
Randomly selecting a person from every household that has been interviewed three times
Randomly selecting a person from every household that has been interviewed twice
Randomly selecting a person from every household that has been interviewed once
I have tried using tag by it does not work with the bysort condition. The same issue is with randomtag. I also tried using egen: max , and then based on this did runiform but it did not work for me. I have attached a sample of the data using dataex.
I am trying to randomly select an individual using the household id. Households have been interviewed in different rounds. Some have been interviewed in all four rounds while some have been interviewed in only 1 or 2 or 3. Based on this information, I am trying to do the following:
Randomly selecting a person from every household that has been interviewed four times
Randomly selecting a person from every household that has been interviewed three times
Randomly selecting a person from every household that has been interviewed twice
Randomly selecting a person from every household that has been interviewed once
I have tried using tag by it does not work with the bysort condition. The same issue is with randomtag. I also tried using egen: max , and then based on this did runiform but it did not work for me. I have attached a sample of the data using dataex.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str4 hhid str1 memid str5 pid str6 visitmonth "1001" "1" "10011" "Mar-14" "1001" "1" "10011" "Sep-14" "1001" "1" "10011" "Jan-14" "1001" "2" "10012" "Feb-14" "1001" "2" "10012" "Mar-14" "1001" "2" "10012" "Apr-14" "1001" "2" "10012" "May-14" "1002" "1" "10021" "Aug-14" "1002" "1" "10021" "Jul-14" "1002" "2" "10022" "Feb-14" "1002" "2" "10022" "Mar-14" "1002" "2" "10022" "Apr-14" end

Comment