Page 1 of 1

Multiplying a scalar by a bunch of years

Posted: Fri Dec 13, 2013 8:31 am
by davey87
Hello,

I have a rate calculated for the year 2012, and population projections for the years 2012-2036.

I want to multiply the rate for 2012 by the population each year from 2012-2036. Currently my code is only multiplying the rate from 2012 by the population from 2012 and giving me NA for the rest of the years.

Ideally I would like to create a for loop that does this for me (i.e., for 2012 to 2036... multiply the 2012 rate by the population each year) however I do not know how to do this.

This is my code:

Code: Select all

'Calculate 2012 Use Rates and create a new page for it pagecreate(page=RATE) a 2012 2012 copy LTC\b* RATE\b* copy(smpl="2012 2012") POP\* RATE\* for %g f m for %c 6569 7074 7579 8084 85plus smpl 2012 2012 series r{%g}{%c}=b{%g}{%c}/p{%g}{%c} next next 'Projections pagecreate(page=PROJ) a 2012 2036 copy POP\* PROJ\* copy RATE\r* PROJ\r* for %g f m for %c 6569 7074 7579 8084 85plus series ltc{%g}{%c} ltc{%g}{%c}=r{%g}{%c}*p{%g}{%c} next next
Is there a simply way to do this?

Alternatively I could copy the rate from 2012 and apply it to every year 2012-2036, but I don't know how to do this either.

Hope you can help.

Thanks

Re: Multiplying a scalar by a bunch of years

Posted: Fri Dec 13, 2013 8:56 am
by EViews Gareth
Could you provide the workfile?

Re: Multiplying a scalar by a bunch of years

Posted: Fri Dec 13, 2013 9:43 am
by davey87
Sure.

See attached

Re: Multiplying a scalar by a bunch of years

Posted: Fri Dec 13, 2013 9:52 am
by EViews Gareth
Given you're dealing with scalar values, you would have been better off using scalar objects or program variables, rather than series. But from where you are, this should work:

Code: Select all

pagecreate(page=PROJ) a 2012 2036 copy POP\* PROJ\* copy RATE\r* PROJ\r* for %g f m for %c 6569 7074 7579 8084 85plus !rate = @elem(r{%g}{%c}, "2012") series ltc{%g}{%c} = !rate*p{%g}{%c} next next

Re: Multiplying a scalar by a bunch of years

Posted: Fri Dec 13, 2013 11:43 am
by davey87
Nice, thank you very much!