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]
Re: st: How can I label a variable with a combination of two value labels
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: How can I label a variable with a combination of two value labels
Date
Fri, 4 Jan 2013 03:06:17 +0000
Spaces in variable labels are not a problem. Your middle line should I
think be more like
label variable var`i'_`j' "`: label lbl_c`j'' `: label lbl_p`i''"
i.e. no spaces after "_c" or "_p".
Nick
On Fri, Jan 4, 2013 at 12:16 AM, Gupta, Ani <[email protected]> wrote:
> Hi Daniel,
>
> Thanks for the response. Yes, I should have referred to them as lbl_c and lbl_p throughout.
>
> I tried using your suggested method, as below:
>
> forvalues i = 1/20 {
> forvalues j = 1/2 {
> label variable var`i'_`j' "`: label lbl_c `j'' `: label lbl_p `i''"
> }
> }
>
> But it didn't work. The problem, I think, is that both sets of labels include multiple words separated by spaces.
>
> Thanks again,
>
> Ani
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of daniel klein
> Sent: Thursday, January 03, 2013 4:01 PM
> To: [email protected]
> Subject: Re: st: How can I label a variable with a combination of two value labels
>
> First, in your code you keep referring to <lbl>, where you should refer to either <lbl_c> or <lbl_p>. However, these migth be typos and it is unlikely they cause the "invalid syntax" errors.
>
> Anyway, if your labels do not contain [compound (double)] quotes, a simple
>
> forv j = 1/2 {
> forv k = 1/20 {
> la var var`j'_`k' "`: label lbl_c `j'' `: label lbl_p `k''"
> }
> }
>
> should do the trick.
>
> If this does not work, I guess we need more information on what your labels look like.
>
> Best
> Daniel
>
> --
> I have two value labels lbl_c and lbl_p that take 2 and 20 values respectively
>
> I also have 40 variables of the type var`i'_`j' where i = 1/2 and `j' = 1/20
>
> I want to label each variable var`i'_`j' with a combination of lbl_c `i' and lbl_p `j'
>
> For a single label I would use -- label variable var`i' "`: label lbl `i' '"
>
> I tried various combinations of quotes of the form -- label variable var`i'_`j' "`"`: label lbl `i' '" "`: label lbl `j' '"'", but I always get a syntax error message.
>
> Does anyone know the correct combination of quotes that would make this work?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/