Statalist


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

Re: st: Incorporating variable labels into the variable name


From   "Tim Wade" <[email protected]>
To   [email protected]
Subject   Re: st: Incorporating variable labels into the variable name
Date   Tue, 11 Sep 2007 16:50:41 -0400

OK, this is close. You can probably get what you need by messing with
the format.

 input v1 v2 v3 v4 v5

           v1         v2         v3         v4         v5
 1. 1 2 3 4 5
 2. end

. label var v1 "9/5/2007"

. label var v2 "9/4/2007"

. label var v3 "9/6/2007"

. label var v4 "9/7/2007"

. label var v5 "9/8/2007"


 foreach var of varlist v1-v5 {
  2. local lab`var': variable label `var'
  3. scalar lab`var'=date("`lab`var''", "mdy")
  4. local lab`var': display %dmDCY lab`var'
  5. rename `var'  rev_`lab`var''
  6. }

. desc

Contains data
  obs:             1
 vars:             5
 size:            24 (99.9% of memory free)
-------------------------------------------------------------------------------
              storage  display     value
variable name   type   format      label      variable label
-------------------------------------------------------------------------------
rev_Sep052007   float  %9.0g                  9/5/2007
rev_Sep042007   float  %9.0g                  9/4/2007
rev_Sep062007   float  %9.0g                  9/6/2007
rev_Sep072007   float  %9.0g                  9/7/2007
rev_Sep082007   float  %9.0g                  9/8/2007
-------------------------------------------------------------------------------
Sorted by:
     Note:  dataset has changed since last saved



On 9/7/07, Rodriguez, Dan <[email protected]> wrote:
>
>
> I have a comma-delimited datafile that I need to process on a daily basis
> within Stata where I need to convert the labels for about 200 columns into
> variable names. The file looks like the following:
>
> acct    name    9/5/2007        9/4/2007        8/31/2007
> 84J     Jacky   1       2       -1
> B88     Mike    -2      3       -1
> B93     Mike    4       5       2
>
>
> When I import this file into Stata I get:
>
> acct            name    v18     v19     v20
> 84J             Jacky   1       2       -1
> B88             Mike    0       0       0
> B93             Mike    0       0       0
>
> . desc
>
> Contains data
>   obs:         1,495
>  vars:           190
>  size:     1,728,220 (83.5% of memory free)
> -------------------------------------------------------------------------------
>               storage  display     value
> variable name   type   format      label      variable label
> -------------------------------------------------------------------------------
> acct            str8   %9s                    Trading Acct
> name            str53  %53s                   Trader
> v18             float  %9.0g                  9/5/2007
> v19             float  %9.0g                  9/4/2007
> v20             float  %9.0g                  8/31/2007
> v21             float  %9.0g                  8/30/2007
> v22             float  %9.0g                  8/29/2007
> v23             float  %9.0g                  8/28/2007
> v24             float  %9.0g                  8/27/2007
> v25             float  %9.0g                  8/24/2007
> v26             float  %9.0g                  8/23/2007
> v27             float  %9.0g                  8/22/2007
> v28             float  %9.0g                  8/21/2007
> v29             float  %9.0g                  8/20/2007
>
> How can I change the variable names to rev_Sep5_2007, rev_Sep4_2007,
> rev_Aug31_2007, etc.?
>
> I need to apply a reshape command to facilitate further analysis.
>
> Thank you,
> Dan Rodriguez
>
> ==============================================================================
Please
> access the attached hyperlink for an important electronic communications
> disclaimer:
>

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================
>
>
>
*
*   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