Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: sum

From   Kit Baum <>
Subject   st: sum
Date   Mon, 31 Oct 2005 12:19:38 -0500

Dirk wrote

I want to assign a dummy if the id (1,2,...13000) is smaller than a threshold
(5000) from another dummy

gen memberh=(id<=sum(member))

But it doesn't work for some reason, it seems sum(member) is always 1, but why?

Recall that generate's sum function is a RUNNING sum, not the total of member. You want egen sum to generate a variable that is a constant across obs. Using auto,

g junk = (price < sum(price))

will be zero in the first obs and 1 thereafter.

But rather than creating a new variable, why not just

summarize member,meanonly
g memberh = (id < r(sum))

Kit Baum, Boston College Economics

* For searches and help try:

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