Search the web
Sign In
New User? Sign Up
statalist · STATA statistical analysis packages users list
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
st: tricky calculation with dozens of variables   Message List  
Reply | Forward Message #65884 of 65887 |
Re: st: tricky calculation with dozens of variables

Xiangping wrote:

There are hundreds of variables from var4 to v389. Now I have to -gen-
total=var4*var8+var15*var19+var26*var30...............
The step of one multiplied pair is 4. The step between the first
variable of one pair and the variable in front of it is 7. Can someone
give me a hint? Or which command or commands can be used here.
-----------------------------------

Use -foreach-; see [P] foreach. I had to start by creating an
artificial dataset; you have your own data, of course.

// create artificial data with 389 variables
clear
set obs 10
forvalues I = 1/389 {
gen var`I' = round(10*uniform())
}

// calculate -total-
generate total=0
forvalues I = 4(11)386 {
local J = `I'+4
replace total = total + var`I'*var`J'
}

Is that what you need?

Svend



________________________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C, Denmark
Phone, work: +45 8942 6090
Phone, home: +45 8693 7796
Fax: +45 8613 1580
E-mail: sj@...
_________________________________________________________

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/



Sat Oct 8, 2005 8:20 pm

SJ@...
Send Email Send Email

Forward
Message #65884 of 65887 |
Expand Messages Author Sort by Date

Dear all, There are hundreds of variables from var4 to v389. Now I have to -gen- total=var4*var8+var15*var19+var26*var30............... The step of one...
Jia Xiangping
jiajoseph@...
Send Email
Oct 8, 2005
7:24 pm

Xiangping wrote: There are hundreds of variables from var4 to v389. Now I have to -gen- total=var4*var8+var15*var19+var26*var30............... The step of one...
Svend Juul
SJ@...
Send Email
Oct 8, 2005
9:10 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help