Bookmark and Share

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]

st: RE: RE: RE: AW: RE: AW: copydesc with a twist??


From   "Ploutz-Snyder, Robert (JSC-SK)[USRA]" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: RE: RE: AW: RE: AW: copydesc with a twist??
Date   Fri, 7 May 2010 13:00:39 -0500

Martin,
Is that the result of the second loop? Or the first??


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Martin Weiss
Sent: Friday, May 07, 2010 12:58 PM
To: [email protected]
Subject: st: RE: RE: AW: RE: AW: copydesc with a twist??


<>


On


Stata/MP 11.0 for Windows (64-bit x86-64)
Born 20 Apr 2010


I get


. d

Contains data
  obs:             1                          
 vars:            20                          
 size:            28 (99.9% of memory free)
----------------------------------------------------------------------------
--------------------
              storage  display     value
variable name   type   format      label      variable label
----------------------------------------------------------------------------
--------------------
a1              byte   %8.0g                  abs(HeadGy)
x1              byte   %8.0g                  HeadGy
a2              byte   %8.0g                  abs(HeadGy)
x2              byte   %8.0g                  HeadGy
a3              byte   %8.0g                  abs(HeadGy)
x3              byte   %8.0g                  HeadGy
a4              byte   %8.0g                  abs(HeadGy)
x4              byte   %8.0g                  HeadGy
a5              byte   %8.0g                  abs(HeadGy)
x5              byte   %8.0g                  HeadGy
a6              byte   %8.0g                  abs(HeadGy)
x6              byte   %8.0g                  HeadGy
a7              byte   %8.0g                  abs(HeadGy)
x7              byte   %8.0g                  HeadGy
a8              byte   %8.0g                  abs(HeadGy)
x8              byte   %8.0g                  HeadGy
a9              byte   %8.0g                  abs(HeadGy)
x9              byte   %8.0g                  HeadGy
a10             byte   %8.0g                  abs(HeadGy)
x10             byte   %8.0g                  HeadGy
----------------------------------------------------------------------------
--------------------



Sure all those single quotes transferred correctly? Some email programs kill
them, so you should also try to obtain the code from the archive.

HTH
Martin

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ploutz-Snyder,
Robert (JSC-SK)[USRA]
Sent: Freitag, 7. Mai 2010 19:54
To: [email protected]
Subject: st: RE: AW: RE: AW: copydesc with a twist??

Hm... I tried this and the second loop merely erased the labels on the a`i'
vars.  What'd I miss??



clear*

. set obs 1
obs was 0, now 1

. forv i=1/10{
  2. gen byte a`i'=1
  3. la var a`i' "abs(x`i')"
  4. gen byte x`i'=1
  5. la var x`i' "HeadGy"
  6. }

. d

Contains data
  obs:             1                          
 vars:            20                          
 size:            24 (99.9% of memory free)
----------------------------------------------------------------------------
------------------------------------------------------------
              storage  display     value
variable name   type   format      label      variable label
----------------------------------------------------------------------------
------------------------------------------------------------
a1              byte   %8.0g                  abs(x1)
x1              byte   %8.0g                  HeadGy
a2              byte   %8.0g                  abs(x2)
x2              byte   %8.0g                  HeadGy
a3              byte   %8.0g                  abs(x3)
x3              byte   %8.0g                  HeadGy
a4              byte   %8.0g                  abs(x4)
x4              byte   %8.0g                  HeadGy
a5              byte   %8.0g                  abs(x5)
x5              byte   %8.0g                  HeadGy
a6              byte   %8.0g                  abs(x6)
x6              byte   %8.0g                  HeadGy
a7              byte   %8.0g                  abs(x7)
x7              byte   %8.0g                  HeadGy
a8              byte   %8.0g                  abs(x8)
x8              byte   %8.0g                  HeadGy
a9              byte   %8.0g                  abs(x9)
x9              byte   %8.0g                  HeadGy
a10             byte   %8.0g                  abs(x10)
x10             byte   %8.0g                  HeadGy
----------------------------------------------------------------------------
------------------------------------------------------------
Sorted by:  
     Note:  dataset has changed since last saved




THEN FOLLOWED BY:

. forv i=1/10 {
  2. la var a`i' "`=subinstr("`:var la  a`i''", "x`i'","`:var la
x`i''",.)'"
  3. }

. d

Contains data
  obs:             1                          
 vars:            20                          
 size:            24 (99.9% of memory free)
----------------------------------------------------------------------------
------------------------------------------------------------
              storage  display     value
variable name   type   format      label      variable label
----------------------------------------------------------------------------
------------------------------------------------------------
a1              byte   %8.0g                  
x1              byte   %8.0g                  HeadGy
a2              byte   %8.0g                  
x2              byte   %8.0g                  HeadGy
a3              byte   %8.0g                  
x3              byte   %8.0g                  HeadGy
a4              byte   %8.0g                  
x4              byte   %8.0g                  HeadGy
a5              byte   %8.0g                  
x5              byte   %8.0g                  HeadGy
a6              byte   %8.0g                  
x6              byte   %8.0g                  HeadGy
a7              byte   %8.0g                  
x7              byte   %8.0g                  HeadGy
a8              byte   %8.0g                  
x8              byte   %8.0g                  HeadGy
a9              byte   %8.0g                  
x9              byte   %8.0g                  HeadGy
a10             byte   %8.0g                  
x10             byte   %8.0g                  HeadGy
----------------------------------------------------------------------------
------------------------------------------------------------
Sorted by:  
     Note:  dataset has changed since last saved

.




-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Martin Weiss
Sent: Friday, May 07, 2010 11:38 AM
To: [email protected]
Subject: st: AW: RE: AW: copydesc with a twist??


<> 


Very true, and I realized it the moment I hit the "send" button. So go ahead
and do this manually:



*************
clear*
set obs 1

forv i=1/10{
	gen byte a`i' =1
	la var a`i' "abs(x`i')"
	gen byte x`i'=1
	la var x`i' "HeadGy"
}

d

//transfer
forv i=1/10{
	la var a`i' "`=subinstr("`:var la  a`i''", "x`i'","`:var la  x`i''"
,.)'"
}

d
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Ploutz-Snyder,
Robert (JSC-SK)[USRA]
Gesendet: Freitag, 7. Mai 2010 18:30
An: [email protected]
Betreff: st: RE: AW: copydesc with a twist??

Indeed, copydesc is an oldie.  But clonevar clones the entire variable,
including the contents.  So using clonevar here would copy over the variable
labels "as-is," without the modification that I desire, and it would also
copy over the CONTENTS of the oldvar to the newvar.

I'm just looking to copy the label from a list of oldvars to a list of
newvars, but also want to add some text to those labels.



-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Martin Weiss
Sent: Friday, May 07, 2010 11:24 AM
To: [email protected]
Subject: st: AW: copydesc with a twist??


<> 

-ssc d copydesc- looks like old code to me, although it may well serve a
useful purpose, and only got like 35 hits last month. It is # 66 on Nick`s
hit list (-ssc hot, auth(cox) n(66)-), but no discussion related to it has
been recorded in the archive since the end of 2003. That could be because
official -clonevar- can do its job more efficiently. Since Nick is the
author of the official command as well, there might be a connection there...



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Ploutz-Snyder,
Robert (JSC-SK)[USRA]
Gesendet: Freitag, 7. Mai 2010 17:37
An: [email protected]
Betreff: st: copydesc with a twist??

I'm looking for a quick way to copy variable labels from a set of variables
(ex. x1-x100) to a set of new variables (ex. a1-a100), but I need a minor
modification of the new labels.

Nicholas' copydesc command comes very close, as I can imbed it in a loop as:

For J in num 1/100: copydesk xJ aJ

But here's the rub.  In this case all of the aJ variables are a
transformation of xJ.  I'd like the transformation to become part of the
variable label too.

Here are two variables as a specific example:

              storage  display     value
variable name   type   format      label      variable label
----------------------------------------------------------------
x2              float  %8.0g                  HeadGy
a2              float  %9.0g                  abs(x2)



I would LIKE the label for a2 to be "abs(HeadGy)"  not "abs(x2)".  I have a
zillion of these, so I don't want to hand-code them all...

Anyone know of an ado already written to do this?  Or a way to use
copydesc??

Much appreciated,
Rob




*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/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/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/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/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/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/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index