I am summing the values of each observation of the weight variable by ID and year. If the values of the "weight" variables are missing, I want the "total weight" value to be missing. Therefore, in my command below I added an option “missing”.
bysort ID year: egen Total weight = total (Weight), missing
However, the value of the Total weight is zero, if I add two or more missing observations. For example in the case of Id “1” year “2002”, the total weight is 0, but I want it to be missing because the two values of weight are both missing.
However, if the group has only one observation and that observation is missing then the total weight is missing, as in the case of 2003 and 2004. Those two cases are ok and good.
However, as I stated above if the group has two or more observations and those observations are missing then total weight values are 0 ( e.g total weight values for 2002, and total weight value for 2005). Please let me know your suggestion on how to fix issues of the zero total weights shown in 2002 and 2005 when they were supposed to be missing.
Thank you very much and I look forward to your tips,
bysort ID year: egen Total weight = total (Weight), missing
However, the value of the Total weight is zero, if I add two or more missing observations. For example in the case of Id “1” year “2002”, the total weight is 0, but I want it to be missing because the two values of weight are both missing.
However, if the group has only one observation and that observation is missing then the total weight is missing, as in the case of 2003 and 2004. Those two cases are ok and good.
However, as I stated above if the group has two or more observations and those observations are missing then total weight values are 0 ( e.g total weight values for 2002, and total weight value for 2005). Please let me know your suggestion on how to fix issues of the zero total weights shown in 2002 and 2005 when they were supposed to be missing.
ID | Year | Weight | Total weight |
1 | 2001 | 126422 | 475262 |
1 | 2001 | 18394 | 475262 |
1 | 2001 | 330446 | 475262 |
1 | 2002 | . | 0 |
1 | 2002 | . | 0 |
1 | 2003 | . | . |
1 | 2004 | . | . |
1 | 2005 | . | 0 |
1 | 2005 | . | 0 |
Thank you very much and I look forward to your tips,
Comment