Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Egen to sum across rows (with an if across rows)

From   Lucy GELDER <>
To   "" <>
Subject   st: Egen to sum across rows (with an if across rows)
Date   Mon, 29 Apr 2013 15:18:14 +0800

Dear Statalist,

I have a dataset which includes 157 columns of times in hours (t1-t157) and 157 columns of categories, with values A - D (cat1-cat157).

I want to sum across the columns by category, so that I end up with four columns timeA-timeD containing the total times for each category.

I have tried:

foreach cat in A B C D{

        egen wardtimeA= rowtotal(wardtime*) if (wardcat*)=="A"


and get the error "wardcat* invalid name". I presume this means I can't use the wild card in the if statement?

Does anyone know of a way I can do this without reshaping to data long.....this is a very large dataset and I would prefer to keep it wide if possible.


Lucy Gelder

This e-mail is confidential. If you are not the intended recipient you must not disclose or use the information contained within. If you have received it in error please return it to the sender via reply e-mail and delete any record of it from your system. The information contained within is not the opinion of Edith Cowan University in general and the University accepts no liability for the accuracy of the information provided.


*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index