Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Re-labelling multiple variables


From   Sergiy Radyakin <serjradyakin@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Re-labelling multiple variables
Date   Mon, 10 Jun 2013 21:24:30 -0400

sysuse auto, clear
ds
local y=2001
foreach v in `r(varlist)' {
  di "`v'"
  label variable `v' `"grsapechildold`y'"'
  local y=`y'+1
}
describe
*** data preparation done
ds
foreach v in `r(varlist)' {
  local l `"`: variable label `v''"'
  local l=subinstr(`"`l'"',"grsapechildold","Dependency Ratio (%), ",.)
  label variable `v' `"`l'"'
}

describe

Best, Sergiy




On Mon, Jun 10, 2013 at 7:58 PM, Konrad <konradedgar@gmx.com> wrote:
> Dear Statlist readers,
>
> I would like to rename a set of variables by replacing a part of a string in variable label with another string. For instance, I imported a number of variables correponding to dependecy ratios. After the import each variable has a label grsapechildoldYEAR, I would like to replace first word with more meaningful text.
>
> local changvrs grsapechildold2003 - grsapechildold2011
> foreach var of varlist `changvrs' {
>         label `var' regexr(`var', "grsapechildold", "Dependency Ratio (%)")
>         }
>
> I don’t know how to mix string replacement commands with variable labelling. As usual, any help will be appreciated.
>
>
>
> --
> Regards
> Konrad
>
>
> *
> *   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/

*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index