I have a data set that looks roughly like this, i.e. individuals in groups. For most but not all individuals I observe a variable value, e.g. income or blood pressure or whatever helps you imagine.
Code:
// Create data set clear set obs 50 egen group = seq(), from(1) to(5) // 5 groups gen indiv = _n // 10 members each generate value = round(runiform()*100, 1) // Value between 1 and 100 gen r = runiform() // Random variable for sorting and for replace value = . if (inrange(r, .02, .1) | inrange(r, .8, .9)) // missing values
Code:
// Choose random value as group value bysort group (r): gen groupvalue = value[1]
Cheers
Nora
0 Response to Choosing random group member observation in the presence of missing values
Post a Comment