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

st: loop 2+ not calculating

From   "William Bishop" <>
Subject   st: loop 2+ not calculating
Date   Mon, 18 Feb 2008 17:59:29 -0800

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

*   For searches and help try:

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