program def chaos
*! NJC 1.0.0 25 November 1998
        version 5.0
        local options "R(real -1) Symbol(str) Connect(str)"
        parse "`*'"

        if `r' <= 0 | `r' >= 4 {
                di in r "need to specify r( ), 0 < r < 4"
                exit 198
        }

        capture set obs 200
        tempvar x t xprev
        qui gen `x' = uniform()
        gen `t' = _n
        label var `x' "x"
        label var `t' "t"
        qui replace `x' = `r' * `x'[_n - 1] * (1 - `x'[_n - 1]) in 2/l
        qui gen `xprev' = `x'[_n - 1]

        if "`symbol'" == "" { local symbol "." }
        if "`connect'" == "" { local connect "l" }
        local title1 "x[t+1] = r * x[t] * (1 - x[t]), r = `r'"
        local title2 "x[t+1] vs x[t]"
        local yvals "0,0.2,0.4,0.6,0.8,1"

        gph open
        gra `x' `t', t1("`title1'") yla(`yvals') xla /*
         */ c(`connect') sy(`symbol') gap(3) l1("x") /*
         */ bbox(0,0,23063,15700,923,444,0)
        gra `x' `xprev', t1("`title2'") yla(`yvals') xla(`yvals') /*
         */ c(`connect') sy(`symbol') gap(3) l1("x[t+1]") /*
         */ b2("x[t]") bbox(0,16300,23063,32000,923,444,0)
        gph close
end