I have a dataset that is a hierarchy set over a maximum of 4 levels where each row is a level in the hierarchy (eg, level 1=fruit, level 2=citrus, level 3=lemon). Below is an example of how the data is structured.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str9 l1 str8(l2 l3) str14 l4 float keep "fruit" "" "" "" 0 "fruit" "citrus" "" "" 0 "fruit" "citrus" "lemon" "" 1 "fruit" "apple" "" "" 1 "fruit" "bannana" "" "" 1 "vegetable" "root veg" "" "" 0 "vegetable" "root veg" "carrot" "" 1 "vegetable" "root veg" "parsnip" "" 1 "vegetable" "root veg" "turnip" "" 1 "vegetable" "root veg" "beetroot" "" 0 "vegetable" "root veg" "beetroot" "white beetroot" 1 "vegetable" "root veg" "beetroot" "red beetroot" 1 "vegetable" "tomato" "" "" 1 end
Is there a way to either automate the creation of the keep variable or collapse the data so that only the fullest rows are retained?
Thank you for any help,
Bryony
0 Response to Keeping most full observation in a hierarchy
Post a Comment