Statalist


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

RE: st: RE: Setting label to adjoining column value


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: Setting label to adjoining column value
Date   Mon, 4 Jan 2010 17:41:15 -0000

Thanks to Eric for his publicity here for -labmask- (SSC and also SJ). 

One of the ways -labmask- can be used is in preparing graphs in which you want to show categories on one or both axes. -search labmask- gives an SJ reference on that topic and two FAQs prepared by the good folks at UCLA: 

. search labmask

Keyword search

        Keywords:  labmask
          Search:  (1) Official help files, FAQs, Examples, SJs, and STBs

Search of official help files, FAQs, Examples, SJs, and STBs


FAQ     .  How to assign the val. of a var. as the val. labels of another var.
        . . . . . . . . . . . . . . . . . .  UCLA Academic Technology Services
        7/08    http://www.ats.ucla.edu/stat/stata/faq/labmask.htm

Example . Code frag.: Hazard ratio of baseline char. by a dichotomous variable
        . . . . . . . . . . . . . . . . . .  UCLA Academic Technology Services
        12/06   http://www.ats.ucla.edu/stat/stata/code/display_hr.htm

SJ-8-2  gr0034  . . . . . . . . . .  Speaking Stata: Between tables and graphs
        (help labmask, seqvar if installed) . . . . . . . . . . . .  N. J. Cox
        Q2/08   SJ 8(2):269--289
        outlines techniques for producing table-like graphs

Nick 
[email protected] 

Eric Booth

Also, NJC's -labutil- utilities are useful for dealing with labels in various ways.  
In this case you could use  -labmask- :

*******
clear*
inp byte col1 str5 col2
1 "Table"
2 "Chair" 
end

ssc install labutil
labmask col1, values(col2) lbl(label)
la li label
*******

On Jan 3, 2010, at 4:51 PM, Martin Weiss wrote:

> " Wasnt aware of the possibility of referencing individual cells like that"
> 
> [U], 13.7., shows you the details...
> 
> BTW, my solution assumes a one to one mapping between col1 and col2, i.e.
> no duplicates. If there are any, -duplicates drop- beforehand...
 
moleps
 
> Beautiful.. Wasnt aware of the possibility of referencing individual cells
> like that.. 

On 3. jan. 2010, at 23.26, Martin Weiss wrote:
 
>> Just go for brute force then:
>> 
>> 
>> *******
>> clear*
>> 
>> inp byte col1 str5 col2
>> 1 "Table"
>> 2 "Chair" 
>> end
>> 
>> l, noo
>> 
>> loc h ""
>> 
>> forv i=1/`=_N'{
>> 	loc h `h' `=col1[`i']' "`=col2[`i']'"
>> }
>> 
>> la def col1 `h'
>> la val col1 col1
>> 
>> //let`s see
>> list, noob
>> la li col1
>> *******
 
Moleps

>> I received an excel dataset with col1 identifiying productnumber, while
> col2
>> has the text variable for the productnumber.
>> Col1 col2
>> 1      Table
>> 2       Chair
>> 
>> etc.,etc
>> 
>> Now what I´d like to do is to automatically generate a label for col1
>> containing col2.
>> 
>> local j=0
>> global h=""
>> 
>> levelsof col2,local (u)
>> foreach var in `u'{
>> local j=`j'+1
>> 
>> global h $h `j'"`""`var'""'"
>> di "$h"
>> 
>> }
>> 
>> 
>> lab define col1 $h
>> lab val col1 col1
>> 
>> The di "$4" displays everything as planned, except for the sorting that
> has
>> been carried out by levelsof. Is there  workaround ? As of now the values
> in
>> the columns dont match. 

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index