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]

st: RE: Re: syntax help


From   "Hardy, Dale S" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: Re: syntax help
Date   Wed, 16 Nov 2011 22:22:21 -0600

Thank you Joseph for all your help. It worked.


________________________________________
From: [email protected] [[email protected]] On Behalf Of Joseph Coveney [[email protected]]
Sent: Wednesday, November 16, 2011 8:35 PM
To: [email protected]
Subject: st: Re: syntax help

Dale S Hardy wrote:

Dear Stata Users,

I am kindly asking for your help. I am defining a macro.

In this macro I would like to calculate a variable called glycemic load for each
subject-1540 subjects.

The formula is:
total gload=Sum[GI of food     * Carbohydrate (gms) of food  * frequency of food
eaten ]

 I have 43 variables for each specific food (GI, Carbohydrate, frequency). Each
food has its corresponding GI, Carbohydrate, and frequency.

 I want to calculate the gload of each food and sum the gloads of all foods to
make a summary gload value for each subject.

[loops and trace omitted]

--------------------------------------------------------------------------------

You don't mention your dataset layout, but from the code it looks like your
dataset has one study participant per observation (row), that there are
variables for for gi, cho and freq for each of the 43 foods, and that these
variables are indexed by a suffix, 1 to 43.  So, how about something like the
following?

generate double gload = 0
quietly forvalues food = 1/43 {
        replace gload = gload + gi`food' * cho`food' * freq`food'
}

Joseph Coveney


*
*   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/

*
*   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