Hi,
my name is Christian, and I am currently trying to depreciate values by years, to generate a "stock-value" out of the "flow-values" meaning values which come up each year.
This stock-value should be a multiplicated number of about 4 times (exactly: 1/0,23) of the first-appearing flow-value, and after that, be decreased each year by 15%. The flow-value should be added. If a year is missing than the decrease should be as if in this year the flow variable was 0, for the next observation available.
Even though I tried to look for previous solutions, I couldn't find a applicable solution:
http://www.stata.com/statalist/archi.../msg00220.html
http://www.statalist.org/forums/foru...-of-a-variable
The problem looks like this:
I would be very happy about any suggestions on how to improve the current code
Best regards,
Christian
my name is Christian, and I am currently trying to depreciate values by years, to generate a "stock-value" out of the "flow-values" meaning values which come up each year.
This stock-value should be a multiplicated number of about 4 times (exactly: 1/0,23) of the first-appearing flow-value, and after that, be decreased each year by 15%. The flow-value should be added. If a year is missing than the decrease should be as if in this year the flow variable was 0, for the next observation available.
Even though I tried to look for previous solutions, I couldn't find a applicable solution:
http://www.stata.com/statalist/archi.../msg00220.html
http://www.statalist.org/forums/foru...-of-a-variable
The problem looks like this:
Code:
Right now:Goal
symbol year patent_amount (flow values) other variables... A 1985 3 ... A 1986 3 ... A 1987 5 ... A 1987 5 ... A 1988 6 B 1990 1 B 1992 2 I tried to solve this problem by myself with this code: sort symbol ayear quietly by symbol: gen first_year = _n gen patentstock=0 replace patentstock=patent_amount*(1/0.23) if symbol != symbol[_n-1] & ayear != ayear[_n-1] & first_year ==1 replace patentstock = patentstock[_n-1]*0.85 + patent_amount if symbol == symbol[_n-1] & ayear-1 == ayear[_n-1] drop patent_amount drop first_year However, the code doesnt work if there are several years for the same symbol, and if there is a gap of years. And I cannot figure out how to solve these issues appropriately.
symbol ayear patent_amount (flow values) patentstock (stock value) other variables... A 1985 3 =3*(1/0,23) ... A 1986 3 =patent_stock_last observed*0,85^1+3 ... A 1987 5 =patent_stock_last observed*0,85^1+5 ... A 1987 5 =patent_stock_last observed*0,85^1+5 ... A 1988 6 ... B 1990 1 =1*(1/0,23) B 1992 2 =patent_stock_last observed*0,85^2+2
I would be very happy about any suggestions on how to improve the current code

Best regards,
Christian
Comment