Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Replace after egen with conditions
From
Miguel Olivo-Villabrille <[email protected]>
To
[email protected]
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/