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

Re: st: concatenate, leading zeros


From   Hugh Davies <[email protected]>
To   [email protected]
Subject   Re: st: concatenate, leading zeros
Date   Mon, 22 Mar 2004 15:33:51 -0800

Title: Re: st: concatenate, leading zeros
Daphna:

Try:

Gen str14 newvar
= string(var1,"%02.0f") + string(var1,"%05.0f") + string(var1,"%07.0f")

Hugh
_________________________________________________
Hugh W. Davies, PhD
Assistant Professor & Graduate Advisor
School of Occupational and Environmental Hygiene,
University of British Columbia
+1 604 822 6777
+1 604 822 9588 (F)





On 3/22/2004 3:23 PM, "daphna" <[email protected]> wrote:

> Hello- I am pretty new to stata and would really appreciate some help with
> what seems like a pretty basic question.
>
> I need to concatenate three variables into 1, and all three may have
> leading zeros.
> Whenever I concatenate, the leading zero's are dropped.
>
> To be clear...
>
> If I have:
>
> var1=01
> var2=04956
> var3=0906730
>
> I would like to get a variable back that is: 01049560906730
>
> This is not what I am getting: instead I am getting 14956906730.
>
> I have formatted all my variables as string with the appropriate
> formats.  For instance, for my variable 1, I have done format var1 %02s.
>
> They all look fine, and retain their leading zero's individually, but not
> once I concatenate.
>
> Any thoughts?
>
> I really appreciate your help with this.
>
>
> =====================================================================
>
> Daphna Bassok
>
> Research Assistant
> Center For Research On Education Outcomes
> Stanford University
> Stanford, CA 94305
>
> Phone: (650) 725-6169
>
> =====================================================================
>
> *
> *   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