Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Creating list of transformed variables


From   "Nick J. Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Creating list of transformed variables
Date   Fri, 23 Jan 2004 16:23:29 -0000

Michael Blasnik pointed to the main
issue, the problem raised by assignment rather than 
copying. 

A secondary detail is that your new names are 
not informative. Provided that your variable 
names are not too long, you can copy them over. 

local difreg 
foreach v of varlist $lhs $rhs2 {
 	gen d`v'=(`v'-`v'[_n-1])/sqrt(2)
 	local difreg "`difreg' d`v'"
}
regress `difreg' 

The initialisation of the macro to an empty string 
is essential only if it already exists. 

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Ken Clark
> Sent: 23 January 2004 12:15
> To: [email protected]
> Subject: st: Creating list of transformed variables
> 
> 
> Dear List
> 
> I'm trying (in Stata 7) to automate the estimation of  a regression
> model on transformed data.  I have a dependent variable, the name
> of which is stored in $lhs, and some independent variables which
> are in $rhs2.  I'd like to transform (quasi-difference) each variable
> and then run a regression on the transformed data.  The code
> below represents my attempt at this.
> 
> global difreg=""
> local i=1
> foreach var of varlist $lhs $rhs2 {
> 	gen d`i'=(`var'-`var'[_n-1])/sqrt(2)
> 	global difreg="$difreg"+" "+"d`i'"
> 	local i=`i'+1
> }
> regress $difreg
> 
> This seems to work fine so long as $rhs2 is not too long.  If there
> are a lot of variables in $rhs2 then Stata stops adding to $difreg
> and the program either stops executing because $difreg is not a
> valid list of variables or (worse) runs with an incomplete list of
> variables.
> 
> I'm sure a more elegant solution exists but am not sure where to
> look.
> 
> Ken
> 
> 
> 
> 
> Ken Clark
> School of Economic Studies
> University of Manchester
> Manchester
> M13 9PL
> Tel:0161-275-3679
> Fax:0161-275-4812
> email: [email protected]
> http://www.ses.man.ac.uk/clark
> *
> *   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/

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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index