Please, help me with the following issue. I need to calculate reserves based on the following idea. Below is a firm (gvkey) and year (fyear) observations of exports (exp). What I want to calculate is as follows. For example, for firm (gvkey) 001013 reserves are expected to be as follow:
Each year the reserve is calculated as an “exp” multiplied by:
Yr1: 10/15
Yr2: 6/15
Yr3: 3/15
Yr4: 1/15
Yr5: 0
Example:
gvkey | fyear | exp | reserve |
1013 | 2003 | 108.6 | 108.6*10/15 |
1013 | 2004 | 59.1 | 108.6*6/15 + 59.1*10/15 |
1013 | 2005 | . | 108.6*3/15 + 59.1*6/15 |
1013 | 2006 | 72 | 108.6*1/15 + 59.1*3/15 + 72*10/15 |
1013 | 2007 | . | 59.1*1/15 + 72*6/15 |
1013 | 2008 | 83.5 | 72*3/15+83.5*10/15 |
1013 | 2009 | 65.3 | 72*1/15+83.5*6/15 + 65.3*10/15 |
1013 | 2010 | 69.7 | 83.5*3/15 + 65.3*6/15+69.7*10/15 |
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str6 gvkey double(fyear exp) "001013" 2003 108.6 "001013" 2004 59.1 "001013" 2005 . "001013" 2006 72 "001013" 2007 . "001013" 2008 83.5 "001013" 2009 65.3 "001013" 2010 69.7 "001019" 1998 . "001019" 1999 . "001019" 2000 . "001019" 2001 . "001021" 1998 2.611 "001021" 1999 1.205 "001021" 2000 .477 "001021" 2001 .457 "001021" 2002 .5 "001021" 2003 .554 "001021" 2004 .397 "001021" 2005 .436 "001021" 2006 .697 "001021" 2007 1.022 "001021" 2008 1.968 "001034" 1998 36.034 "001034" 1999 40.168 "001034" 2000 43.276 "001034" 2001 86.65 "001034" 2002 67.088 "001034" 2003 63.232 "001034" 2004 81.466 "001034" 2005 26.936 "001034" 2006 44.43 "001034" 2007 140.255 "001036" 1998 17 "001036" 1999 29 "001036" 2000 . end
0 Response to Create a variable based its proportion
Post a Comment