Statalist


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

st: RE: local=0802 vs. local=802


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: local=0802 vs. local=802
Date   Mon, 16 Jun 2008 18:07:18 +0100

As Kit Baum points out, Stata [not STATA, please] won't treat 0802 as such unless you make it clear that you want a literal, i.e. string, interpretation of 0802. 

local j 0802 

will suffice but 

local j "0802" 

is more transparent to the reader. 

In your example, that is the only point to watch out for. 

If you had started at 0302 and your next was 0702, 1102, etc. the code could have been 

local j "0302" 

* within loop 
local j = `j' + 400 
local j : di %04.0f `j' 

Nick 
n.j.cox@durham.ac.uk 

Man Jia

I was wondering how to successfully defining local macros beginning 
with 0, since I think probably STATA automatically ignores the 0 in the 
beginning of a local's expression.

my data set has following variables:
-----------
T0990802
T0991302
T0991802
T0992302
T0992802
T0993302
T0993802
T0994302
------------
I want to create new variables equal the value of 2006 subtracted by 
T0990802, T0991302,... and T0994302.
I tried the following command:
------------------------------------------
local j=0802
forvalue i =1/8 {
g age`i'=2006-T099`j'
replace age`i'=2006-T099`j'
local j=`j'+500
}
end
-----------------------------------------
But STATA gives the error information :
" T099802 not found
  r(111); "

I guess it's probably because STATA treats "local j=0802" as "local j 
=802". How could I make the 0 in 0802 not ignored?


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