Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

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 n.j.cox@durham.ac.uk 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/

**References**:**st: changing formatting of values stored in r()***From:*Leslie Liang <G.L.Liang@warwick.ac.uk>

- Prev by Date:
**st: AW: AW: Reorganization of pael data** - Next by Date:
**st: New versions of -addinby- and -rtfutil- on SSC** - Previous by thread:
**st: changing formatting of values stored in r()** - Next by thread:
**st: AW: changing formatting of values stored in r()** - Index(es):