Statalist


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

Re: st: Incorporating variable labels into the variable name


From   "David Elliott" <dcelliott@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Incorporating variable labels into the variable name
Date   Thu, 13 Sep 2007 13:23:44 -0300

Just an observation, Michael, your solution didn't thread into the
topic in my mail program, although it is properly threaded in the
Archive.  It happens sometimes (actually, all the time) that replies
to threads don't properly thread and can get missed.

I very much like your solution as it is quite parsimonious of code,
although with a different dataset having a number of datatypes the
destringing process might not be as easy.  While I didn't implement it
originally, I think I would simply use the variable label next time
combining some of my code and Michael's to produce:

 X--------begin---------X

clear

insheet using c:\ado\test\testfile.raw

foreach V of varlist _all {
  local date=date("`:variable label `V''","mdy")
  if "`date'" !="." { // variable has label in date format
	local year=year(`date')
	local monthday:di  %dmd `date'
	local vname= "rev_"+trim("`monthday'")+"_"+trim("`year'")
	rename `V' `vname'
	}
  }

list
reshape long rev_ , i(acct) string
list

 X--------end---------X

I think this combines the best of both approaches.

DC Elliott
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index