From: "Nick Cox" <firstname.lastname@example.org>
Subject: RE: st: how to merge two variables into one
Date: Mon, 28 Nov 2005 11:29:33 -0000
The help for -egen, concat()- is
concat(varlist) [, format(%fmt) decode maxlength(#) punct(pchars)]
may not be combined with by. It concatenates varlist to produce a
string variable. Values of string variables are unchanged. Values
of numeric variables are converted to string, as is, or converted
using a format under option format(%fmt) or decoded under option
decode, in which case maxlength() may also be used to control the
maximum label length used. By default, variables are added end to
end: punct(pchars) may be used to specify punctuation, such as a
space, punct(" "), or a comma, punct(,).
That is, the -format()- option specifies a numeric format to
be used in the mapping to string. It does not specify a
string format to be used for the string variables themselves.
A glance at the code using
. viewsource _gconcat.ado
shows that the argument of -format()-, when supplied, is
passed to the -string()- function, which takes a real
argument and optionally a numeric format.
Thus you need to apply -format- after the -egen- call.
> thanks nick for your reply. it turns out that -trim()- was
> not what i was
> looking for. i managed to get what i want (99% of it in any
> case) by trial
> and error with helps from the manual (i looked at append,
> merge, trim and
> searched for concat, where i stumbled upon egen option that
> did the trick).
> this is the command that i used:
> egen studynyr = concat (study year), punct(" ")
> i tried to right justify the apperance of studynyr by adding
> format (%15s)
> i.e.: egen studynyr = concat (study year), format (%15s) punct(" ")
> but keep getting 'Invalid format'. however when i list the
> data, appearance
> seems to be as i like it so i might not have to force right
> but i would still appreciate advice on how to get the right
> command correct.
> >When you say merge, I guess you mean
> >Assumed that you have applied -trim()-,
> >right-alignment is a matter of format,
> >not of what the values are, nor of how
> >they are held informally.
> >You should read up the help on formats.
> > > i have two variables: studynames and yearofstudy e.g. Alshop
> > > 1981, Bell 1992.
> > >
> > > what i want to do is to merge the two variables such that:
> > > Alshop 1981
> > > Bell 1992
> > > i.e. somehow it is right-aligned in each cell.
> > >
> > > would be grateful for help in achieving this.
> > >
> > > platform: stata 8.2, os wxp pro sp2.
* For searches and help try: