*! 1.2.0 NJC 24 March 1999
* 1.1.2 NJC 12 May 1998
* 1.0.0 NJC 19 June 1997
program def sssplot
    version 6.0
    syntax varlist(min=3 max=3) [if] [in] , [ *  STart(int 1) SF(str) /*
    */ XLAbel(str) L1title(str) LA(str) GBYM F(int 12) Symbol(str) Connect(str)]

    if `start' > `f' {
        di in r "start( ) should not be greater than f( )"
        exit 198
    }

    tokenize `varlist'
    args data month year

    preserve
    if "`if'`in'" != "" { qui keep `if' `in' }
    tempvar x block

    if `start' != 1 {
        #delimit ;
        qui replace `month' =
    	 cond(`month' >= `start', `month' - `start' + 1,
	     `month' + `f' - `start' + 1) ;
        #delimit cr
    }
    fillin `month' `year'

    su `year', meanonly
    local ymin = r(min)
    local ymax = r(max)

    if "`sf'" != "" {
        tempvar sm
        egen `sm' = `sf'(`data'), by(`month')
	label var `sm' "`sf'"
        if "`l1title'" == "" {
            local l1title : variable label `data'
            if "`l1title'" == "" { local l1title "`data'" }
        }
    }

    if "`symbol'" == "" { local symbol "sy(oi)" }
    else local symbol "sy(`symbol')"
    if "`connect'" == "" { local connect "c(.L)" }
    else local connect "co(`connect')"

    if "`gbym'" != "" {
        sort `month' `year'
        qui by `month' : gen `block' = -sum(`data' == .)
        sort `month' `block' `year'
        if "`xlabel'" == "" { local xlabel "xla(`ymin',`ymax')" }
        else local xlabel "xla(`xlabel')"
        gra `data' `sm' `year', /*
	*/ `xlabel' `symbol' `connect' `options' by(`month') l1(`"`l1title'"')
    }
    else {
        gen `x' = `month' + (`year' - `ymin') / (`ymax' - `ymin') - 0.5

        if `f' == 4 { local period "quarterly " }
        else if `f' == 12 { local period "monthly " }
        label var `x' "`period'subseries of `1'"

        if "`la'" == "" {
            if `f' == 4 { local la "JFM AMJ JAS OND" }
            else if `f' == 12 {
                local la "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
            }
        }
        if "`la'" != "" {
            tokenize `la'
            local m = cond(`start' == 1, 1, 2 + `f' - `start')
	    tempname xlbl
            while "`1'" != "" {
                label def `xlbl' `m' "`1'", modify
                local m = cond(`m' == `f', 1, `m' + 1)
                mac shift
            }
            label val `x' `xlbl'
        }

        su `month', meanonly
        local mmin = r(min)
        local mmax = r(max)
        if "`xlabel'" == "" {
            if `mmax' - `mmin' < 20 { local xlabel "xla(`mmin'/`mmax')" }
            else local xlabel "xlabel"
        }
        else local xlabel "xla(`xlabel')"

        gen `block' = sum(`data' == .)
        gsort - `month' - `block' `year'

        gra `data' `sm' `x', /*
	*/ `symbol' `connect' `xlabel' `options' l1("`l1title'")
    }
end