Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: New variable based on a sum of products of another variable


From   "Seamer Paul" <[email protected]>
To   <[email protected]>
Subject   RE: st: New variable based on a sum of products of another variable
Date   Wed, 25 May 2011 14:39:30 +0100

Many thanks to Nick and Paul for their suggestions,

Apologies that it’s taken me a while to reply.

Paul’s iterative solution is a neat answer to the question I posed, but there was an additional step that I didn’t mention in my original post,

I need to multiply each of the product terms (in parentheses in my original post) by another 2 variables before I perform the summation,

Essentially I’m looking generate a probability (P) that is of the form,

(P)= ∑ {var1} {var2} { ∏ var3 }

My original post related to calculating the sum product of var3, but I need to do this for different values of each variable and then perform a summation for each time period.

Nick's hint led me to a solution using logarithms ? it has a number of steps, but gives the answer I was looking for,
The values x are chronological years and i values are age in years (I'm using the probabilities to populate an illness-death Markov-type model).

.forvalues x = 1903/1997 {
.forvalues i = 1/41 {
.gen p`x'`i' = exp(sum(ln(var3`x')) - sum(ln(var3`x'[_n-`i']))) * var2`x'[_n-(`i'-1)]
.replace p`x'`i' = p`x'`i' * var1`x'[_n-`i'] if _n>=`i'+1
.}
.forvalues j = 2/41 {
.replace p`x'1 = p`x'1 + p`x'`j' if _n>=`j'
.}
.drop p`x'2-p`x'41 
.rename p`x'1 p`x' 
.}
 
________________________________

Paul Seamer
Email: [email protected]



This email and any attachment is intended solely for the recipient. Its unauthorised use, disclosure, storage or copying is not permitted. If you are not the intended recipient please destroy all copies and inform the sender by return e-mail.. The information contained in this email may be subject to public disclosure under the NHS Code of Openness or the Freedom of Information Act 2000. Unless the information is legally exempt from disclosure, the confidentiality of this e-mail and your reply cannot be guaranteed. All emails are monitored for security reasons. Any views or opinions expressed are solely those of the author and do not necessarily represent those of NHS West Midlands. In the interests of the environment please think carefully before printing this email.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index