Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: strange problem


From   "Anthony Gichangi" <[email protected]>
To   "stata liste" <[email protected]>
Subject   st: strange problem
Date   Thu, 1 Jul 2004 13:01:47 -0500

I am trying to run the following code on my dataset but I get
a strange error which I  don't understand, any ideas

CODE:

des drug fmtab
set trace on
qui sum drug
preserve
bysort prn : keep if _n==1
forvalues x = 1(1)`r(max)' {
qui sum fmtab if drug ==`x', de
local med`x' = `r(p50)'
di `med`x''
}
restore


RESULTS:


des drug fmtab

              storage  display     value
variable name   type   format      label      variable label
----------------------------------------------------------------------------
---
drug            long   %15.0g      drugc
fmtab           float  %9.0g

. set trace on
. qui sum drug
. preserve
. bysort prn : keep if _n==1
(296782 observations deleted)
. forvalues x = 1(1)`r(max)' {
  2. qui  sum fmtab if drug ==`x', de
  3. local   med`x' =   `r(p50)'
  4.
. di `med`x''
  5. }
- forvalues x = 1(1)`r(max)' {
= forvalues x = 1(1)25 {
- qui sum fmtab if drug ==`x', de
= qui sum fmtab if drug ==1, de
- local med`x' = `r(p50)'
= local med1 = .3703703582286835
- di `med`x''
= di .3703703582286835
.37037036
- }
- qui sum fmtab if drug ==`x', de
= qui sum fmtab if drug ==2, de
- local med`x' = `r(p50)'
= local med2 =
invalid syntax
  di `med`x''
  }

Strange enough,  the median for drug 2 is not missing because i have over
200 observations


I tried to simulate a similar dataset and use the same code strange enough
it works for the new data
set


clear

. set obs 1000
obs was 0, now 1000

. gen fmtab =uniform()

. gen drug =int(uniform()*8)

. gen prn =int(uniform()*100)

.
. qui sum drug

. preserve

. bysort prn : keep if _n==1
(900 observations deleted)

.
.
. forvalues x = 1(1)`r(max)' {
  2. qui  sum fmtab if drug==`x',de
  3. local   med`x'   = `r(p50)'
  4. di `med`x''
  5. }
.39820221
.66737372
.59730798
.44514874
.36423917
.56873959
.64900935

. restore

Any ideas ?

Kind Regards
Anthony

*
*   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