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]

From |
"Saporito, Salvatore J" <sjsapo@wm.edu> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
st: How do I create a loop that calculates new variables by performing the simple mathematical function of subtracting one varlist on another varlist? |

Date |
Mon, 9 Jan 2012 02:47:44 +0000 |

I am trying to subtract one sequential list of variables (e.g., a1 to a73) from another sequential list (e.g., b1 to b73) using a loop statement such as the "foreach..." I am trying to avoid repeating the same, simple function (in this case 73 times). Specifically, I want a loop that repeats this: gen h7a001=h7r001-h7t001 gen h7a002=h7r001-h7t002 to gen h7a073=h7r003-h7t073 Simple question but I am trying to learn Stata so that I can use the power of its programming capabilities. This particular challenge eludes me. Thanks, Sal * * 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/

**Follow-Ups**:**Re: st: How do I create a loop that calculates new variables by performing the simple mathematical function of subtracting one varlist on another varlist?***From:*James Sams <sams.james@gmail.com>

**st: RE: How do I create a loop that calculates new variables by performing the simple mathematical function of subtracting one varlist on another varlist?***From:*"Philip Ryan" <philip.ryan@adelaide.edu.au>

- Prev by Date:
**Re: st: stcox in case the ph-assumption is rejected** - Next by Date:
**st: RE: How do I create a loop that calculates new variables by performing the simple mathematical function of subtracting one varlist on another varlist?** - Previous by thread:
**st: Accumulated mean and standard deviation** - Next by thread:
**st: RE: How do I create a loop that calculates new variables by performing the simple mathematical function of subtracting one varlist on another varlist?** - Index(es):