Using the data below, the new variable would contain a value of 6957.976 for all ADM1's coded Abia. The regions coded
Adamawa would get a value of 14700.07, because that is the year 2000 value.
I have tried the following which gives me the correct value, but only for 1 year:
I have tried the following which gives me the correct value, but only for 1 year:
Code:
gen newvar=din_mean if year==2000
Then I tried,using conditional statements which are invalid:
Code:
generate newvar=din_mean cond(year==2000), cond(adm1_name)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float din_mean int year str43 adm1_name 6957.976 2000 "Abia" 7199.941 2001 "Abia" 7354.144 2002 "Abia" 7363.155 2003 "Abia" 7377.722 2004 "Abia" 7254.504 2005 "Abia" 7626.5 2006 "Abia" 6957.407 2007 "Abia" 7300.354 2008 "Abia" 6579.216 2009 "Abia" 6472.372 2010 "Abia" 6383.461 2011 "Abia" 6405.632 2012 "Abia" 5937.302 2013 "Abia" 5652.877 2014 "Abia" 14700.07 2000 "Adamawa" 14990.18 2001 "Adamawa" 15624.333 2002 "Adamawa" 15763.845 2003 "Adamawa" 15278.785 2004 "Adamawa" 14968.954 2005 "Adamawa" 14709.36 2006 "Adamawa" 14060.687 2007 "Adamawa" 13661.188 2008 "Adamawa" 12903.557 2009 "Adamawa" 12320.458 2010 "Adamawa" 11599.244 2011 "Adamawa" 11389.64 2012 "Adamawa" 11338.117 2013 "Adamawa" 10938.296 2014 "Adamawa" 8998.419 2000 "Akwa Ibom" 9408.253 2001 "Akwa Ibom" 9630.833 2002 "Akwa Ibom" 9760.444 2003 "Akwa Ibom" 9997.468 2004 "Akwa Ibom" 9802.899 2005 "Akwa Ibom" 10291.298 2006 "Akwa Ibom" 9392.056 2007 "Akwa Ibom" 9967.786 2008 "Akwa Ibom" 8957.063 2009 "Akwa Ibom" 8943.704 2010 "Akwa Ibom" 8820.957 2011 "Akwa Ibom" 8834.809 2012 "Akwa Ibom" 8160.992 2013 "Akwa Ibom" 7656.95 2014 "Akwa Ibom" 8730.578 2000 "Anambra" 8964.393 2001 "Anambra" 9166.87 2002 "Anambra" 9263.745 2003 "Anambra" 9230.272 2004 "Anambra" 9056.286 2005 "Anambra" 9306.192 2006 "Anambra" 8666.584 2007 "Anambra" 8898.282 2008 "Anambra" 8183.067 2009 "Anambra" 8003.974 2010 "Anambra" 7915.148 2011 "Anambra" 7949.56 2012 "Anambra" 7306.759 2013 "Anambra" 7032.423 2014 "Anambra" 27628.03 2000 "Bauchi" 28053.086 2001 "Bauchi" 28912.09 2002 "Bauchi" 28842.91 2003 "Bauchi" 28677.21 2004 "Bauchi" 28507.38 2005 "Bauchi" 28147.77 2006 "Bauchi" 28729.293 2007 "Bauchi" 26408.467 2008 "Bauchi" 27391.12 2009 "Bauchi" 27321.43 2010 "Bauchi" 26423.55 2011 "Bauchi" 26260.105 2012 "Bauchi" 26548.31 2013 "Bauchi" 26759.914 2014 "Bauchi" 5512.152 2000 "Bayelsa" 5720.31 2001 "Bayelsa" 5738.026 2002 "Bayelsa" 5817.795 2003 "Bayelsa" 5681.693 2004 "Bayelsa" 5451.026 2005 "Bayelsa" 5485.681 2006 "Bayelsa" 5132.689 2007 "Bayelsa" 5348.476 2008 "Bayelsa" 4771.2183 2009 "Bayelsa" 4678.9272 2010 "Bayelsa" 4713.195 2011 "Bayelsa" 4783.924 2012 "Bayelsa" 4453.332 2013 "Bayelsa" 4267.915 2014 "Bayelsa" 16739.164 2000 "Benue" 17293.713 2001 "Benue" 17904.361 2002 "Benue" 17877.084 2003 "Benue" 18381.033 2004 "Benue" 18449.107 2005 "Benue" 18789.283 2006 "Benue" 18050.193 2007 "Benue" 17966.035 2008 "Benue" 17230.775 2009 "Benue" end
0 Response to Generate new variable based on existing data
Post a Comment