Multiplying a scalar by a bunch of years

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

davey87
Posts: 24
Joined: Tue Feb 05, 2013 12:18 pm

Multiplying a scalar by a bunch of years

Postby davey87 » Fri Dec 13, 2013 8:31 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Multiplying a scalar by a bunch of years

Postby EViews Gareth » Fri Dec 13, 2013 8:56 am

Could you provide the workfile?

davey87
Posts: 24
Joined: Tue Feb 05, 2013 12:18 pm

Re: Multiplying a scalar by a bunch of years

Postby davey87 » Fri Dec 13, 2013 9:43 am

Sure.

See attached
Attachments
nl.wf1
(77.13 KiB) Downloaded 296 times

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Multiplying a scalar by a bunch of years

Postby EViews Gareth » Fri Dec 13, 2013 9:52 am

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

davey87
Posts: 24
Joined: Tue Feb 05, 2013 12:18 pm

Re: Multiplying a scalar by a bunch of years

Postby davey87 » Fri Dec 13, 2013 11:43 am

Nice, thank you very much!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests