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'" <statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: "Label define" syntax for "all other values" |

Date |
Fri, 24 Sep 2010 13:26:19 +0100 |

Indeed. There are many possibilities here, but all I think with disadvantages as well as advantages. For example, if what is driving this is a desire for graphs and/or tables of simplified classifications, then you could write wrapper programs that produce versions of the variables in question on the fly. Nick n.j.cox@durham.ac.uk Dan Waldo Thank you, Nick. Having 2 distinct approaches is a consolation for not having the 3rd approach. Creating a second variable is a clean and viable option, although I suspect its viability fades as the number of variables needing this treatment increases. --- On Fri, 9/24/10, Nick Cox <n.j.cox@durham.ac.uk> wrote: > The straight answer is that -label > define- does not offer the syntax imagined. In addition to > Eric's strategy, another is > > clonevar rr_job2 = rr_job > replace rr_job2 = 5 if !inlist(rr_job, 1, 2, 3, 4) > label def rr_job2 1 "Driver" 2 "Conductor" 3 "Brakeman" 4 > "Fireman" 5 "Stata user" > label val rr_job2 rr_job2 > > -recode- is here naturally an alternative to -replace-. Dan Waldo > Thanks, Eric ... Your advice has put me on the right track > (sorry about the pun). > > I see that rearranging the code one can accommodate values > of interest that appear less neatly among the possible > values: > > ******** > levelsof rr_job , local(lev) > foreach x in `lev' { > lab def rr_jobf `x' "All Other Jobs", modify > } > > lab def rr_jobf 1 "Driver" 5 "Conductor" 6 "Brakeman" 12 > "Fireman", modify > > lab li > lab val rr_job rr_jobf > ******** > > I had thought that perhaps there was a compact way to do > this, akin to the SAS FORMAT procedure syntax: > value rr_jobf 1="Driver" 5="Conductor" 6="Brakeman" > 12="Fireman" other="All other jobs"; > > ... but such is life. Fri, 9/24/10, Eric Booth <ebooth@ppri.tamu.edu> > > lab def rr_jobf 1 "Driver" 2 "Conductor" 3 "Brakeman" > 4 > > "Fireman", modify > > > > levelsof rr_job if rr_job>4, local(lev) > > foreach x in `lev' { > > lab def > > rr_jobf `x' "All Other Jobs", modify > > } > > > > lab li > > lab val rr_job rr_jobf Dan Waldo > > > Suppose that variable rr_job takes the values > > 1,2,3,...,999. Can I construct a format for this > variable > > that specifies some values and lumps the rest into a > > catchall category? That is, can I write > > > > > > label define rr_jobf 1 "Driver" 2 "Conductor" 3 > > "Brakeman" 4 "Fireman" <other> "All other jobs" > > > > > > where <other> represents the syntax I don't > know > > but means any value not elsewhere specified. * * 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**:**RE: st: "Label define" syntax for "all other values"***From:*Nick Cox <n.j.cox@durham.ac.uk>

**RE: st: "Label define" syntax for "all other values"***From:*Dan Waldo <dan_waldo@yahoo.com>

- Prev by Date:
**RE: st: "Label define" syntax for "all other values"** - Next by Date:
**st: Writing a value from a variable into a macro** - Previous by thread:
**RE: st: "Label define" syntax for "all other values"** - Next by thread:
**Re: st: "Label define" syntax for "all other values"** - Index(es):