Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: For each observation, total values |

Date |
Tue, 5 Jul 2011 18:19:53 +0100 |

We can't comment on your code because you don't give any. The -egen- function -anycount()- appears to be what you want. If your real question is how it works you can inspect its insides by e.g. . viewsource _gcount.ado Nick On Tue, Jul 5, 2011 at 5:51 PM, Zach Levin <zlevin@stanford.edu> wrote: > I have month variables that can take on different values for each month, that is MONTH_1 might be equal to 0 while MONTH_3 might be equal to 1. What I would like to do is create a loop that generates a variable equal to the number of months where the value equals 1 (or 0 or 3 etc). The problem is, every time I create a loop it replaces the value for ALL the observations, but I really just want to know for each observation how many months the value is set to a certain number. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: For each observation, total values***From:*Zach Levin <zlevin@stanford.edu>

**References**:**st: For each observation, total values***From:*Zach Levin <zlevin@stanford.edu>

- Prev by Date:
**Re: st: Average marginal effects after heckprob** - Next by Date:
**st: Re: Stata code for calculating Zivot-Andrews unit root test in presence of structural break** - Previous by thread:
**st: For each observation, total values** - Next by thread:
**Re: st: For each observation, total values** - Index(es):