Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: extract portion of variable name to use in variable label


From   philippe van kerm <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: RE: extract portion of variable name to use in variable label
Date   Mon, 9 Jun 2008 18:14:32 +0200

Assuming X is the variable name, something like this should work:

        label variable X `" `=substr("X",3,length("X")-5)' `: variable label X' "'

where
        `=substr("X",3,length("X")-5)'  extracts the relevant string from the variable name.
        `: variable label X'            returns the initial variable label

For looping through a long list of variables, you can put the line in a -foreach- loop:

foreach var of varlist your_list_of_variables {
        label variable `var' `" `=substr("`var'",3,length("`var'")-5)' `: variable label `var'' "'
}

Not tested, but I imagine something along these lines should work.

Philippe



> -----Message d'origine-----
> De : [email protected] [mailto:owner-
> [email protected]] De la part de Martin Weiss
> Envoy� : lundi 9 juin 2008 17:29
> � : [email protected]
> Objet : st: RE: extract portion of variable name to use in variable
> label
>
> -h extended_fcn- might help you with the extraction process...
>
> Martin Weiss
> _________________________________________________________________
>
> Diplom-Kaufmann Martin Weiss
> Mohlstrasse 36
> Room 415
> 72074 Tuebingen
> Germany
>
> Fon: 0049-7071-2978184
>
> Home: http://www.wiwi.uni-tuebingen.de/cms/index.php?id=1130
>
> Publications: http://www.wiwi.uni-
> tuebingen.de/cms/index.php?id=1131
>
> SSRN:
> http://papers.ssrn.com/sol3/cf_dev/AbsByAuth.cfm?per_id=669945
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Andy
> Baxter
> Sent: Monday, June 09, 2008 5:27 PM
> To: [email protected]
> Subject: st: extract portion of variable name to use in variable
> label
>
> I have a large data set in which the variable names reflect the
> subject
> and metric of a specific test, e.g., a_alg1_ss is the "Algebra 1
> Scale
> Score."
> All of the variable names have a common structure:  a prefix of a_,
> a
> test identifier string, and a suffix of _[metric of test, e.g., al
> for
> achievement level or ss for scale score].
> The current variable labels reflect the test metric, but not the
> test
> identifier.
>
> Here is a subset of the variables:
>
> . describe  a_alg1_ss   a_alg1_al a_alg1rt1_ss   a_alg1rt1_al
>
>               storage  display     value
> variable name   type   format      label      variable label
> -------------------------------------------------------------------
> ---------
> ---
> a_alg1_ss       int    %8.0g                   Scalescore
> a_alg1_al       byte   %8.0g                   Achievement Level
> a_alg1rt1_ss    int    %8.0g                   Scalescore
> a_alg1rt1_al    byte   %8.0g                   Achievement Level
>
> I am trying to write syntax that will extract the test identifier
> from
> the variable name and insert it into the variable label.  I would
> like
> to wind up with:
>
> variable name                     variable label
> a_alg1_ss                           alg1 Scalescore
> a_alg1_al                           alg1 Achievement Level
> a_alg1rt1_ss                       alg1rt Scalescore
> a_alg1rt1_al                        alg1rt Achievement Level
>
> My Stata version is:
>  .about
> Stata/SE 9.2 for Windows
> Born 20 Jul 2007
>
> Thanks for your consideration.
> --
> Andy Baxter
> Center for Research & Evaluation
> Charlotte-Mecklenburg Schools
> 980.343.1603 (phone)
> 980.343.6660 (fax)
>
>
>
> Email correspondence to and from this address is subject to public
> records
> requests  pursuant to the North Carolina Public Records Law,
> resulting in
> monitoring and potential disclosure of this message to third
> parties.
>
> In compliance with federal law, Charlotte-Mecklenburg Schools
> administers
> all education programs, employment activities and admissions
> without
> discrimination against any person on the basis of gender, race,
> color,
> religion, national origin, age or disability.
>
> *
> *   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/
>
> *
> *   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/

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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index