title: Creating a Table Using Previous Values (Iterative Process)
body: <p>I'm completely new to Visual FoxPro (9.0) and I was having trouble with creating a table which uses previous values to generate new values. What I mean by this is I have a given table that is two columns, age and probability of death. Using this I need to create a survival table which has the columns Age, l(x), d(x), q(x), m(x), L(x), T(x), and q(x) Where:</p>
  <ul>
  <li>l(x): Survivorship Function; Defined as l(x+1) = l(x) * EXP(-m(x))</li>
  <li>d(x): Number of Deaths; Defined as l(x) - l(x+1)</li>
  <li>q(x): Probability of Death; This is given to me already</li>
  <li>m(x): Mortality Rate; Defined as -LN(1-q(x))</li>
  <li>L(x): Total Person-Years of Cohorts in the Interval (x, x+1); Defined as l(x+1) + (0.5 * d(x))</li>
  <li>T(X): Total Person-Years of all Cohorts in the Interval (x, N); Defined as SUM(L(x)) [From x, N]</li>
  <li>e(x): Remaining Life Expectancy; Defined as T(x) / l(x)</li>
  </ul>
  <p>Now I'm not asking how to get all of these values, I just need help getting started and maybe pointed in the right direction. As far as I can tell, in VFP there is no way to point to a specific row in a data-table, so I can't do what I normally do in R and just make a loop. I.E. I can't do something like:</p>
  <pre><code>for (i in 1:length(given_table$Age))
    {
    new_table$mort_rate[i] &lt;- -LN(1-given_table$death_prop[i])
    }
  </code></pre>
  <p>It's been a little while so I'm not sure that's 100% correct anyway, but my point is I'm used to being able to create a table, and alter the values individually by pointing to a specific row and/or column using a loop with a simple counter variable. However, from what I've read there doesn't seem to be a way to do this in VFP, and I'm completely lost.</p>
  <p>I've tried to make a Cursor, populating it with dummy values and trying to update each value sequentially using a SCATTER NAME and SCAN/REPLACE thing, but I don't really understand what's happening or how to fine tune this each calculation/entry that I need. (This is the post I was referencing when I tried this: <a href="https://stackoverflow.com/questions/60133518/multiply-and-subtract-values-in-previous-row-for-new-row-in-foxpro">Multiply and subtract values in previous row for new row in FoxPro</a>.</p>
  <p>So, how do I go about making a table that relies on iterative process to calculate subsequent values in Visual FoxPro? Are there any good resources that explain Cursors and the Scatter/Scan thing that I was trying (I couldn't find any resources that explained it in terms I could understand)?</p>
  <p>Sorry if I've worded things poorly, I'm fairly new to programming in general. Thank you.</p>