More importantly, Scott's approach gives incorrect results:
+--------------+
| round year |
|--------------|
| 1992 1992 |
| 1993 1993 |
| 1996 1994 |
| 1998 1995 |
| 2000 1996 |
| 2001 1998 |
| 2002 2000 |
| 2003 2001 |
| 11 2002 |
| 12 2003 |
+--------------+
But I like the idea of doing it yourself, with a -foreach- loop:
count if mi(year)
if r(N)>0 error 1001
count if mi(round)
if r(N)>0 error 1001
qui levels year, local(y)
foreach yr of local y {
su round if year==`yr', meanonly
if r(max)!=r(min) {
di as err "Round not constant within year"
error 134
}
local roundlab `roundlab' `=r(min)' "`yr'"
}
la def round `roundlab'
la val round round
Note also the inclusion of some minimal error-checking, which you will
really want when working with multiple files, in case some contain
errors.
On 2/11/06, Michael Blasnik <[email protected]> wrote:
> I don't think this does what they asked -- this creates value labels that
> are sequential values labeled with the values of a variable -- in fact it
> does what -encode- does more directly. The question was about labeling the
> values of one variable using the values of another -- a slightly trickier
> problem. I've written an ado that does this but haven't posted it to SSC
> (no help file, not fully gracious with errors). I could send a copy
> off-list if Caleb would like.
>
> ----- Original Message -----
> From: "Scott Merryman" <[email protected]>
> >
> > levelsof year, local(levels)
> > local i = 1
> > foreach l of local levels {
> > local mylabels "`mylabels' `i' `l'"
> > local ++i
> > }
> > label define label `mylabels'
> > label values round label
> >
> >> -----Original Message-----
> >> From: Caleb Southworth
> >> Is there a convenient way to convert the values of one variable into
> >> labels? For example, if rounds of survey are given in a particular year,
> >> then
> >> round | Summary of year
> >> number | Mean Std. Dev. Freq.
> >> ------------+------------------------------------
> >> 1 | 1992 0 4763
> >> 2 | 1993 0 6037
> >> 5 | 1994 0 2787
> >> 6 | 1995 0 2650
> >> 7 | 1996 0 2611
> >> 8 | 1998 0 2651
> >> 9 | 2000 0 2733
> >> 10 | 2001 0 3201
> >> 11 | 2002 0 3339
> >> 12 | 2003 0 3351
> >> ------------+------------------------------------
> >> Total | 1996.8892 3.9638084 34123
*
* 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/