Bookmark and Share

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]

st: Replace after egen with conditions


From   Miguel Olivo-Villabrille <m.olivo@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Replace after egen with conditions
Date   Mon, 12 Nov 2012 15:12:34 -0700

Hi all,

I have a panel data set, I am trying to compute totals by date for
observations that match certain conditions:

bys date2: egen total_supply=total(supply) if dispatched=="Y" & big==1

this will give me what I want but it will only assign that total to
observations that match the conditions. I am interested in producing a
constant variable within dates that has that (total for observations
that match the conditions) but assigned to all observations
regardless. Any ideas how I might accomplish this?
I tried

bys date2: replace total_supply=total_supply[_n-1] if total_supply==.

but that solves the problem for the bottom observations within date,
and not the observations before the condition is met. Also, adding

bys date2: replace total_supply=total_supply[_n+1] if total_supply==.

will only change the one observation before the condition is met

Any suggestions are welcome

Miguel
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index