[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
RE: st: concatenate, leading zeros
I am unclear what Daphna is doing here.
A format like "%02s" can only be applied to
string variables. In my experiments, it has
the effect of inserting leading spaces in the
display, not leading zeros. (Or what I am doing wrong,
However, the display format as set by -format-
has no effect on the values of a variable.
Hugh's advice, which we can revise to
gen str14 newvar =
is on the contrary appropriate to _numeric_
Note that -egen, concat()- won't work here,
as it is crucial that different formats are used.
Hugh Davies replied to Daphna Bassok
Gen str14 newvar = string(var1,"%02.0f") + string(var1,"%05.0f") + string(var1,"%07.0f")
> 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:
> 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.
* For searches and help try: