Statalist The Stata Listserver

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


From   Dirk Nachbar <>
To   hklui <>
Subject   st: SETAR
Date   30 Jun 2006 09:18:41 +0100


unfortunately I am not working on the SETAR model at the moment.

below is a rudimentary Stata program which has to be debugged and finalised. Maybe someone from the list can help me and you. The array var at the end should store the variances of all possible models and then the one with lowest variance should be output.

good luck,



Program for Self-Exciting Threshold AutoRegressive model



set obs 100

gen time=_n

tsset time

gen y=0

replace y=(1+0.3*l.y)*(y>0)+(0+0.5*l.y)*(y<=0)+0.5*invnorm(uniform()) if time>1

line y time

capture program drop setar

program define setar

    version 8.2

    syntax varlist [if] [in], ar(int 1) steps(int 10)

    marksample touse

    qui count if `touse'

    if r(N) ==0 {

            error 2000


    if `ar'<1     {

            di as error "the AR component must be bigger than 1"

            exit 198



    if `steps'<5 {

            di as error "you should have at least 5 steps"

            exit 198


    qui sum `1'

    local min r(min)

    local max r(max)

    local y `1'

    forval i=1/`steps' {

                    tempvar y`i' y`i'inv

                    gen y`i'=l.(y>`min'+`i'*(`max'-`min')/`steps')

                    gen y`i'inv=1-y`i'

                    forval j=1/`ar' {

                                    tempvar y`i'`j' y`i'inv`j'

                                    gen y`i'`j'=l`j'.y*y`i'

                                    gen y`i'inv`j'=l`j'.y*y`i'inv


                    qui reg y y`i' y`i'1-y`i'`ar' y`i'inv y`i'inv1-y`i'inv`ar'

                    *store the variance and threshold

                    mat var[`i',1]=(e(rmse)*e(rmse)*e(df_r)/e(N))

                    mat var[`i',2]=`min'+`i'*(`max'-`min')/`steps'



Dirk Nachbar

Assistant Economist


Department for Work and Pensions

Level 4, The Adelphi

1-11 John Adam St

WC2N 6HT London

020 796 28531 30/06/2006 07:42 To Dirk Nachbar/London/Asd@ASD cc Subject Help: Stata and SETAR


********************************************************************** This document is strictly confidential and is intended only for use by the addressee. If you are not the intended recipient, any disclosure, copying, distribution or other action taken in reliance of the information contained in this e-mail is strictly prohibited. Any views expressed by the sender of this message are not necessarily those of the Department for Work and Pensions. If you have received this transmission in error, please use the reply function to tell us and then permanently delete what you have received. Please note: Incoming and outgoing e-mail messages are routinely monitored for compliance with our policy on the use of electronic communications. **********************************************************************
The original of this email was scanned for viruses by Government Secure Intranet (GSi) virus scanning service supplied exclusively by Cable & Wireless in partnership with MessageLabs.
On leaving the GSI this email was certified virus free.
The MessageLabs Anti Virus Service is the first managed service to achieve the CSIA Claims Tested Mark (CCTM Certificate Number 2006/04/0007), the UK Government quality mark initiative for information security products and services. For more information about this please visit

Attachment: UNKNOWN.htm
Description: UNKNOWN.htm

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