Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: RE: mapping a value from 2 variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: mapping a value from 2 variables
Date   Fri, 26 Jul 2002 12:52:54 +0100

[email protected]
> 
> To recap this thread:  In response to my posting where I 
> expressed my wish
> to avoid explicit looping over observations to create a 
> value label mapping
> between a numeric variable and a string variable, Michael 
> Blasnik suggested
> the following approach:

< snip > 
> 
> Nick Cox had previously suggested

< snip > 
> 
> To compare the relative efficiency of both solutions, I put 
> together two
> separate routines, one using the -forvalue- approach, the 
> other using the
> -outsheet- line.  I then compared their relative 
> performance (see table
> below).

< snip > 
> 
> maplab2 turned out to be much faster!  It's running the .do 
> file in in
> maplab1 which is time consuming.  Here's a quick tabulation
> 
>                   seconds elapsed
>                     ----------
> obs ('000s)    maplab1     maplab2
> ------------+----------------------
>      1      |     .3         .2
>      3      |    1.1        1.3
>      5      |    4.7        2.7
>      7      |   11.6        4.2
>      9      |   21.8        5.6
>     30      |  300.3       21.2
> 
> where we have a different value label for each observation.
> 
> I'll go with maplab2 then.  Thanks all.
> 

I'll add two comments: one is trivial 
and the other is less so. 

1. Anyone wanting to copy Patrick's program -maplab2- 
should note that he has left wired into three lines 
his original variable names 

>             local val = naics[`i']
>             local label = labelnaics[`i']
>             label def naicslab `val' "`label'" , modify

The correction is just to generalise to use `1', `2' 
and `labname'. 

2. The results seem fairly clearcut, but I'll repeat an 
earlier caution that even relative timings dependent on I/O can 
vary according to machine, OS and set-up (e.g. 
whether you are using Stata on your "own" machine
or over a network). In preparing an FAQ on a different 
question which is at 

http://www.stata.com/support/faqs/data/savesome.html

and trying to distill which method of two was faster, 
Paul Seed, Jean Marie Linhart and I found what were 
to me surprising contradictions, with my "own" Stata 7 under
Windows XP being the odd one out. 

Nick 
[email protected] 
*
*   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