Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: loop 2+ not calculating


From   "Rajesh Tharyan" <[email protected]>
To   <[email protected]>
Subject   st: RE: loop 2+ not calculating
Date   Tue, 19 Feb 2008 02:24:00 -0000

Hi,

Try this..

webuse grunfeld, clear
su time, meanonly
loc Max=r(max)
g mdn=.
 forval t = 2/`Max' {
sort company
 by company: egen temp=median(kst) if time<`t'
 by company: replace mdn=temp[`t'-1] if time==`t'
 drop temp
 }

Hope this helps

Rajesh



-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of William Bishop
Sent: 19 February 2008 01:59
To: [email protected]
Subject: st: loop 2+ not calculating

I'm trying to create a median for the previous observations (not
including the current observation) by company .  The code below works
for the first loop (company 1) but after that it just has missing
values for the median.  I don't understand why.  Any ideas on what I'm
doing wrong.

webuse grunfeld, clear
su time, meanonly
loc Max=r(max)
levelsof com, local(is)
g mdn=.
foreach i of local is {
 forval t = 2/`Max' {
 egen temp=median(kst) if com==`i'&time<`t'
 qui replace mdn=temp[`t'-1] if com==`i'&time==`t'
 drop temp
 }
}


William
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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