Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: problem with describe and r(varlist)


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: problem with describe and r(varlist)
Date   Mon, 27 Nov 2006 00:56:22 -0000

There is no limit to r(varlist) that will bite you. 
That is not the point. The point is that when you go 

local macname = r(varlist) 

there is a limit on the length of the macro named macname. 

You can get round this by copying, not evaluating, as in

local macname "`r(varlist)'" 

but my advice pivoted on the further point that you don't 
need to use the macro in any case. 

Nick 
[email protected] 

Daniel Becker
 
> Nick, thanks for your quick response.
> 
> I am using stata 9.2 as well, on a mac, the intercooled version
> 
> my workaround to this limit in r(varlist) was to first apply ds to  
> all variables that are not string variables (I do not want to  
> tabulate all string variables anyway..)
> 
> So this worked
> 
> quietly ds, not(type string);
> local AlleVariablen = r(varlist);
> 
> foreach x of local AlleVariablen {;
> codebook `x', compact;
> tabulate `x';
> };
> 
> Thanks for your code and your hint about help limits - I 
> wasn't aware  
> that I am doing things that make those limits relevant.
> 
> Daniel
> 
> PS: I posted to the list the first time. Doesn't the listserver send  
> me my own message? I only saw Nick's responses coming in....
> 
> 
> Am 27.11.2006 um 01:04 schrieb Nick Cox:
> 
> > I guess that your line
> >
> > local AlleVariablen = r(varlist)
> >
> > evaluated, not copied. Thus the limit on
> > the length of a string in a string expression
> > (see -help limits-) bit you.
> >
> > Actually, I am a bit puzzled, as in my version
> > of Stata, 9.2, -describe, simple- does not leave behind
> > r(varlist) -- contrary to [D] describe and your example.
> >
> > Anyway, your code can be slimmed down to cut the
> > middle macro:
> >
> > ds
> > foreach x of var * {
> > 	codebook `x', compact
> > 	tabulate `x'
> > }
> >
> > Nick
> > [email protected]
> >
> > Daniel Becker
> >
> >> I am trying to loop over all names of variables in the memory. to
> >> prepare for that, I want to prepare a local that lists all my
> >> variables. I thought that r(varlist) stores them, but, as you see
> >> below, the "descibe, simple" commmand gives me all my variables, it
> >> stores only a subset in r(varlist).
> >>
> >> Does anyone know why that happens?
> >>
> >> Thanks for any hint,
> >>
> >> daniel
> >>
> >>
> >>
> >> #### from my do-file
> >>
> >> describe, simple;
> >> display r(varlist);
> >> local AlleVariablen = r(varlist);
> >> display "Im local AlleVariablen steht: " "`AlleVariablen'";
> >>
> >> foreach x of local AlleVariablen {;
> >> codebook `x',compact;
> >> tabulate `x';
> >> };
> >>
> >>
> >> #### stata-output from the log
> >>> describe, simple;
> >> res_id       B6           B15          B24          C5_1
> >> E4_sonst     F5_konkret
> >> start        B7           B16          B25          C5_2
> >> E5           F6
> >> ende        - B8           B16_andere   B26          C5_3
> >> E6           F6_konkret
> >> A1           B9_1         B17          C1           D1
> >> E7           F7
> >> A2           B9_2         B17_sonst    C2           D1_andere
> >> E8           F7_konkret
> >> A2_sonst     B10          B18          C3_1         D2
> >> E9           G1
> >> A3           B10_konkret  B18_sonst    C3_2         D3
> >> E10          G2
> >> A4           B11          B19          C3_3         D4
> >> E10_andere   G3
> >> B1           B11_sonst    B20          C3_4         E1
> >> E11          A1_erstf
> >> B2           B12          B20_konkret  C4_1         E1_sonst
> >> F1           A1_zweitf
> >> B3           B12_sonst    B21          C4_2         E2           F2
> >> B4           B13          B21_sonst    C4_3         E2_konkret   F3
> >> B5           B13_mehr     B22          C4_4         E3           F4
> >> B5_sonst     B14          B23          C4_5         E4           F5
> >>
> >>  display r(varlist);
> >> res_id start ende A1 A2 A2_sonst A3 A4 B1 B2 B3 B4 B5 
> B5_sonst B6 B7
> >> B8 B9_1 B9_2 B10 B10_konkret B11 B11_son
> >>> st B12 B12_sonst B13 B13_mehr B14 B15 B16 B16_andere B17
> >> B17_sonst
> >> B18 B18_sonst B19 B20 B20_konkret B21 B2
> >>> 1_sonst B22 B23 B24 B25 B26
> >>
> >> #### the variables C1 ... D1 ... etc are missing in r(varlist)
> >>

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