Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: RE: changing formatting of values stored in r()


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: changing formatting of values stored in r()
Date   Wed, 14 Apr 2010 11:34:13 +0100

There are two issues here. 

1. Your error message arises because you need to specify the -modify-
option of -label-. 
The value label already exists, so you can't overwrite it willy-nilly
without signalling that you know that you are changing it. 

2. Independently of that, your manipulations need an extra detail. As
discussed recently on this list, something like `r(r1)' has a local
macro persona -- which is why your first syntax worked -- but something
like 

`string(`r(r1)',`"%9.2f"'

does not get extended the same generosity. You need 

`= string(`r(r1)',"%9.2f")'

Note that I took out a stray ` (left quote). The `= ' serve to indicate
that whatever is inside should be evaluated on the fly.

Incidentally, I am surprised at the statement that 

display `string(`r(r1)',`"%9.2f")'

works and have not been able to reproduce that. 

Note that r() results are ephemeral, so all this must be done
immediately after -_pctile-. 

Nick 
[email protected] 

Leslie Liang

I'm trying to label a variable by the values stored in r() but am having
difficulties getting the labels formatted correctly

xtile var2=var1, nq(5)
_pctile var1, nq(5)
ret list
lab define var2 1 "<`r(r1)'" 2 "`r(r1)'<`r(r2)'" 3 "`r(r2)'<`r(r3)'" 4
"`r(r3)'<`r(r4)'" 5 "<`r(r4)'"

I have a new variable, var2, split in 5 quantiles and I would like to
label them based on the the r() returned from -_pctile-. I then proceed
to define the labels as shown above, but the number of dec places are
too many. I would just like them to follow "%9.2f" but i can't seem to
specify it anywhere.

alternatively, I have tried:

lab define var2 1 `"`string(`r(r1)',`"%9.2f"')'"'
invalid attempt to modify label
r(180);

but I keep getting an error. Is there something wrong with my syntax? I
am still able to use -display `string(`r(r1)',`"%9.2f"'- to get the
formatting I desire, but I can't seem to fit it into -lab define-.


*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index