Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Scaling of variables


From   Maarten Buis <maartenlbuis@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Scaling of variables
Date   Tue, 7 Jun 2011 10:22:23 +0200

On Tue, Jun 7, 2011 at 10:05 AM, Achmed Aldai wrote:
> What would be my lname and do I use in or of list? I have like 30 variables that have to be scaled by at.
> If I use of what would be the name of my varlist or can I just set a random name for that?
>
> Concerning the macros, I would do it with ds [varlist], I guess the name from above and then say var/at?

Here is an example of what I think you want to do. You want to divide
many variables by one variable. In these cases it is sometimes easier
to specify the variables you do not want to divide rather than the
variables you do want to divide. You can do so with the -not- option
in -ds-. -ds- also has other useful shortcuts, that can help you, see
-help ds-. After that it is just a matter of storing the returned
varlist in a macro, and than loop over the elements of that macro.

Below is an example:

*---------------- begin example -------------------
sysuse auto, clear

// assume that make is your id variable
// and weight your scaling variable
ds make weight, not

local vars "`r(varlist)'"

foreach var of local vars {
	gen sc_`var' = `var' / weight
	label var sc_`var' "scaled version of `var'"
}
*---------------- end example --------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index