Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: sd() does not work with forvalues |
Date | Sat, 16 Jul 2011 10:13:13 +0100 |
-egen- calls. NickOn 15 Jul 2011, at 18:31, Richard Goldstein <richgold@ix.netcom.com> wrote:
my guess is that the error message refers to the line that starts "gennosddff`i'" rather than to the egen line -- and that line shouldn't work outside the loop either; however, you have already calculated this valueand saved it in a variable so why not use that variable at that point? i.e., change the line to gen nosddff`i'=diffmedi`i'/sddf`i' Rich On 7/15/11 1:20 PM, Wilhelm Kluemper wrote:Hello STATA community, I am trying out a code where I want to create the standard deviation of a var as a new var with a loop: dfbeta forvalues i = 3/85 { egen df`i'med = median(_dfbeta_`i') egen sddf`i'= sd(_dfbeta_`i') gen diffmedi`i'=_dfbeta_`i'-df`i'med gen absdiffmedi`i' = abs(diffmedi`i') gen nosddff`i'= diffmedi`i'/sd(_dfbeta_`i') drop if nosddff`i'>=2 } I keep getting this message: unknown function sd() It works perfectly without the forvalues loop but not within. Does anybody have a clue why that is and what I could do about it? Thanks already Wilhelm* * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/
* * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/