I want to create a LogMiscellaneousExpenditure variable of each household (denoted by hhid14) consisting of their expenditures for three item categories (denoted by ks3type). However, because there are multiple duplicates of the variable, I want to remove them but still keeping household id that has 0 expenditure values in the dataset. The example of data that I use is as follows:
ks3type hhid14 logMiscellaneousExp
E 0010600 0
F 0010600 11.69525
G 0010600 0
E 0010651 0
F 0010651 12.76569
G 0010651 0
E 0010800 0
G 0010800 0
F 0010800 0
E 0010851 0
G 0010851 0
F 0010851 0
F 0012200 0
E 0012200 22.51503
G 0012200 22.51503
G 0012241 0
E 0012241 33.0063
F 0012241 33.0063
G 0012242 14.07788
F 0012242 0
E 0012242 0
G 0012251 0
F 0012251 0
E 0012251 0
F 0012400 0
G 0012400 12.61154
E 0012400 0
E 0012451 10.12663
G 0012451 0
F 0012451 0
E 0012452 19.67914
F 0012452 0
G 0012452 19.67914
previously I have tried two commands:
i) duplicate drop hhid14, force -> but this command will delete some output variable values
ii) sort hhid14 logMiscellaneousExp
egen tag = tag(logMiscellaneousExp) -> but this command will only recognize the first row of expense variables that have a value, and remove variables from some households that have a value of 0. Thanks in advance!
ks3type hhid14 logMiscellaneousExp
E 0010600 0
F 0010600 11.69525
G 0010600 0
E 0010651 0
F 0010651 12.76569
G 0010651 0
E 0010800 0
G 0010800 0
F 0010800 0
E 0010851 0
G 0010851 0
F 0010851 0
F 0012200 0
E 0012200 22.51503
G 0012200 22.51503
G 0012241 0
E 0012241 33.0063
F 0012241 33.0063
G 0012242 14.07788
F 0012242 0
E 0012242 0
G 0012251 0
F 0012251 0
E 0012251 0
F 0012400 0
G 0012400 12.61154
E 0012400 0
E 0012451 10.12663
G 0012451 0
F 0012451 0
E 0012452 19.67914
F 0012452 0
G 0012452 19.67914
previously I have tried two commands:
i) duplicate drop hhid14, force -> but this command will delete some output variable values
ii) sort hhid14 logMiscellaneousExp
egen tag = tag(logMiscellaneousExp) -> but this command will only recognize the first row of expense variables that have a value, and remove variables from some households that have a value of 0. Thanks in advance!
Comment