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

st: Re: Creating list of transformed variables


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: Creating list of transformed variables
Date   Fri, 23 Jan 2004 09:22:09 -0500

Don't use = and + signs to put together a long string or else you'll hit
Stata's limit of 80 (or 244 for SE?) characters.  Instead

global difreg "$difreg d`i'"

will do what you want (although I'm not sure why you aren't using local
instead of global)

Michael Blasnik
[email protected]

----- Original Message ----- 
From: "Ken Clark" <[email protected]>
To: <[email protected]>
Sent: Friday, January 23, 2004 7:15 AM
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


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