Statalist


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

st: RE: -foreach-, local macro, -split- command


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: -foreach-, local macro, -split- command
Date   Tue, 8 Sep 2009 22:37:35 +0100

String variables can not include more than 244 characters. Period. 

Beyond that, I really don't get a clear picture of the precise problem.
I'd recommend 

1. Take a step back. Talk about the problem and the goal. 

2. Show some example data. 

3. Where you are now within your coding is less important.  

Nick 
[email protected] 

David Torres

I have a minor problem working with a local macro created within a  
loop command (-forv-), which is followed by another loop command  
(-foreach-).  This is the deal:

1.  I lead with a -levelsof- command, then store the values in a local
macro.
2.  I call the local macro in a -foreach- command, replacing a  
previously generated variable with the values therein.
3.  My values are actually strings and take up a bit of space within  
the one variable created for them (Stata only allows up to 244  
characters for string variables).  This means that some of the values  
don't get recorded.
4.  The -split- command works wonderfully at creating a different  
variables for the multiple responses recorded into the single variable  
filled from my local macro.

My question is this:  Is there some way I can call the values in my  
local macro and record them into different variables without having to  
fill the limited space Stata allows in a variable?

I guess this would be a one-to-many split, but without a variable to  
actually split.  The information for splitting would be stored in  
another form or something.

If I have 5000 students who have each scored differently on IQ scales  
at several times over several years and their position in the  
distribution are stored as strings (mentally retarded, borderline, low  
normal, etc.), some of the observations will, when called in the  
-foreach- command, exceed the 244 character limit.

This is sort of what I'm doing:

levelsof wais, local(lev)
foreach l of lev {
   replace generatedvar="`l' "...
  }

split generatedvar

Everything else works fine; I'm just missing those values (strings and  
portions thereof) in excess of 244 characters.

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index