I am trying to balance an unbalanced panel in order to create a set of datasets that have the same exact structure. I am aware that one can do calculations in Stata with an unbalanced panel, but that is not my goal.
My unbalance panel looks like this:
There are two dimensions: the country and the group. I am seeking to balance the "group" variable for each household ("hh") for each country. For example, in country x, HH1 consumes all the group items that I want every household to have: shoes, rent, tomato and ham. HH 2 in country x; however, consumes all the "group" items except for "ham". I am seeking a way that I can add missing group categories like "ham" in household 2 in country X to all household missing a group in each country. The "exp" variable for this missing group would be 0, but the group would still be there.
This is what I am ultimately after (notice that the number of household is not the same in both countries x and y. This is OK)
Any suggestions and/or advice would be of much help. Thank you.
My unbalance panel looks like this:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str1 country byte hh str6 group int exp byte weight "x" 1 "shoes" 320 3 "x" 1 "rent" 398 3 "x" 1 "tomato" 100 3 "x" 1 "ham" 217 3 "x" 2 "shoes" 426 4 "x" 2 "rent" 423 4 "x" 2 "tomato" 536 4 "x" 3 "shoes" 372 5 "x" 3 "rent" 141 5 "y" 1 "shoes" 182 3 "y" 1 "rent" 508 3 "y" 2 "shoes" 419 4 "y" 3 "shoes" 586 5 "y" 3 "rent" 207 5 "y" 4 "shoes" 142 6 "y" 4 "rent" 462 6 "y" 4 "tomato" 430 6 "y" 5 "ham" 177 20 end
This is what I am ultimately after (notice that the number of household is not the same in both countries x and y. This is OK)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str1 country byte hh str6 group int exp byte weight "x" 1 "shoes" 320 3 "x" 1 "rent" 398 3 "x" 1 "tomato" 100 3 "x" 1 "ham" 217 3 "x" 2 "shoes" 426 4 "x" 2 "rent" 423 4 "x" 2 "tomato" 536 4 "x" 2 "ham" 0 4 "x" 3 "shoes" 372 5 "x" 3 "rent" 141 5 "x" 3 "tomato" 0 5 "x" 3 "ham" 0 5 "y" 1 "shoes" 182 3 "y" 1 "rent" 508 3 "y" 1 "tomato" 0 3 "y" 1 "ham" 0 3 "y" 2 "shoes" 419 4 "y" 2 "rent" 0 4 "y" 2 "tomato" 0 4 "y" 2 "ham" 0 4 "y" 3 "shoes" 586 5 "y" 3 "rent" 207 5 "y" 3 "tomato" 0 5 "y" 3 "ham" 0 5 "y" 4 "shoes" 142 6 "y" 4 "rent" 462 6 "y" 4 "tomato" 430 6 "y" 4 "ham" 0 6 "y" 5 "shoes" 0 20 "y" 5 "rent" 0 20 "y" 5 "tomato" 0 20 "y" 5 "ham" 177 20 end
Comment