I can't make much sense of this, but it looks like fantasy
syntax to me, i.e. what you think might work if Stata worked
the way you would like it to. I guess that you are trying
to mix syntax for manipulating strings with syntax for
generating variables.
Working backwards, -egen, rowtotal()- will only accept
(names of) numeric variables, because its one and only job is to
calculate row totals from numeric values. It won't
work with more general expressions.
Also, if you are using string variables, then comparing them
with numbers is illegal.
The whole problem, as you saw earlier, is that which
variables you want to use varies from observation to
observation. You could use -egen, rowtotal()-
to solve your problem if and only if the variables
you feed to it are missing (or 0) when you want to ignore them.
No doubt that could be arranged, but it is just a round-about
way of doing what you already know how to do.
Nick
[email protected]
Mungai, Edward
> Sorry this should have been egen -rowtotal-. No mystery.
>
> I still would have liked to figure out how to pass variables
> to -rowtotal- which would have made my task easier.
>
> Below is part of what I tried given that variables -age- and
> - year- are known. Sorry it may be too basic stata for most
> people and I prefer readable long code!.
>
> generate yr16 = year - age + 16
>
> generate yr18 = yr16 + 2
>
> tostring startyr, generate(yr16)
>
> tostring stopyr, generate(yr18)
>
> generate startpos = "sehead" + startyr if (yr16>=1968)
>
> generate stoppos = "sehead" + stopyr if (yr18<=2005)
>
> generate timespan = "("+startpos + " - " + stoppos+")"
>
> egen prsemp = rowtotal(sehead1968 sehead1969 sehead1970)
> From: [email protected] on behalf of Nick Cox
> Sent: Fri 4/27/2007 10:09 AM
> To: [email protected]
> Subject: RE: st: Looping across variables in variable columns
>
>
>
> Glad you were helped by the responses.
>
> Meanwhile, the mystery of what -rowcount- is remains.
>
> Nick
> [email protected]
>
> Mungai, Edward
>
> > Thank you all who gave ideas on this querry.
> >
> > Being new to stata I have chosen and managed to implement
> > solution 1B and taken into consideration other comments
> > relating to missing values. I am motivated to learn more stata!.
>
> n j cox
>
> > I can't find -rowcount- using -findit- or Google. Recall the
> > precept in
> > the Statalist FAQ:
> >
> > "Say what command(s) you are using. If they are not part of official
> > Stata, say where they come from: the STB/SJ, SSC, or other
> archives."
> >
> > That said, this is a nice problem. It has got enough spin (cricket
> > sense, not public relations!) to be interesting, yet yields
> > to a little knowledge of Stata.
>
> ...
>
> Mungai, Edward <[email protected]>
>
> > I have seen discussions on looping across an unknown number
> of columns
> > which can be solved by -reshape-.
> >
> > My question is how to sum across columns where the number of columns
> > varies from one observation to the next. i.e. I may need to
> > sum columns
> > 2 to 5 for the first observation but from columns 4 to 11 for the
> > second observation. In all cases the summation is done
> across a set of
> > adjacent columns.
> >
> > I have tried to use -rowcount-, and the looping functions
> > but as far as
> > I can tell all sum across a fixed number of columns from one
> > observation
> > to the next. But there is something good also; the
> information on the
> > column to begin and the column to end the summation for each
> > observation is contained in two adjacent column which are
> > the same for
> > all the observations.
>
> *
> * 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/
>
>
>
>
> This message has been scanned for viruses by TRENDMICRO,
> an IESE technology affiliate company and global leader in
> antivirus and content security software.
>
> *
> * 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/
>
*
* 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/