Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Andreas Karpf <andreas.karpf@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: Calculate weighted average across variables with externally given weights - controlling for missing values [quite urgent] |
Date | Mon, 3 Oct 2011 03:16:45 +0200 |
Dear statalist-Users, i am really sorry that my first post on this list contains a [urgent] in the subject line. i know that pushiness like that is not appreciated on such mailing lists, but it is what it is and i hope for your kind understanding. I have a got a question which might seem quite trivial for a lot of you but despite of googeling for several hours i couldn't find any solution. I have a couple of time series variables for different industrial sectors like manufacturing, services industry, communication industry etc. t ; var_sect_1 ; var_sect_2 ; var_sect_3 ; var_sect_4; jan ; ; ; ; ; feb ; ; ; ; ; mar ; ; ; ; ; apr ; ; ; ; ; What I want to do (example january): weight_avg_january= var_sect_1[jan] *weight_sect_1 + var_sect_2[jan]*weight_sect_2 + var_sect_3[jan]*weight_sect_3 + var_sect_4[jan]*weight_sect_4/(weight_sect_1+weight_sect_2+weight_sect_3+weight_sect_4) if there is however a missing value for january sector 1 it should look like: weight_avg_january= var_sect_2[jan]*weight_sect_2 + var_sect_3[jan]*weight_sect_3 + var_sect_4[jan]*weight_sect_4/(weight_sect_2+weight_sect_3+weight_sect_4) these data relates to a kind of business monitor survey and i would like to calculate the aggregate indicator by using sectorial weights, this means weights which correspond to the contribution of each sector (services, manufacturing) to the gdp. i at first though i could do that by hand but than i realized that 1) if there is one missing value in e.g. sector 1 in january stata outputs a missing value for the weighted average for january. so it doesn't just ignore the mv but it refuses to calculate the datapoints which are there. 2) even if problem number one would be solved of course the denominator would not be correct because if the sector 1 data in january is missing also the weight in the denominator for sector 1 should be omitted. The weights i am referring to are from an external statistic. I have really tried everything, tried read every ressource possible, but i didn't come to a conclusion. it would be absolutely nice if you could help me. best regards, andreas * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/