Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Implemenation Stata 11 ado.file


From   "Catharina Klepsch" <[email protected]>
To   [email protected]
Subject   st: Implemenation Stata 11 ado.file
Date   Tue, 20 Jul 2010 12:02:41 +0200

Dear Stata Users

Below you will find an extract of an ado.file(xttest) which I would like to implement(Stata Version 11.0), but there are still some problems I could not solve:

1.
I would like to insert an option, which allows to lag the exogenous variables. If I do xttest y l.x1 l.x2 I get a problem with step 3, because the mean variables should be calculated from the x (without lag)! I tried several things but I really did not find an appropriate solution…

2.
Furthermore is it possible to add an option to the xttest program to insert yeardummies but without calculating the lags and means of the yeardummies? A solution is not to insert yeardummies at Step 5 (xttobit y x yeardummies), because the program should be applicable to different datasets

3.
Step 5 does xttobit, with intm(gh) ll(0) ul(1), but is it also possible to insert an option where  the ll and ul specifications are used as the person using xttest wishes?


For any comments I would be very grateful!
Best regards Catharina

*******************************************************************
capture program drop xttest
program define xttest , eclass sortpreserve byable(recall)

                                
version 11.0
syntax varlist(ts) [if] [in]

    *** Split varlist into dependent and independent variables:
        tokenize `varlist'
        local regressand `1'
        macro shift
        local regressors `*'
        

      *** Check if the dataset is tsset:
        qui tsset
        local panelvar `r(panelvar)'
        local timevar  `r(timevar)'
        *generate year Dummyvariables
        *capture tabulate `timevar', gen (yearDum)
        
                if "`panelvar'"=="" {
                di as err "must specify panelvar and timevar; use xtset"
                exit 459
        }
        
***1.Step
*** generate lag variables for the endogenous variable
foreach x of local regressand {
by `panelvar': generate lag`x' = `x'[_n-1]
}

***2.Step
*** generate lag variables for the exogenous variables
foreach x of local regressors{
capture quietly by `panelvar': generate lag`x' = `x'[_n-1]
}

***3.Step
***generate for all independent Variables the mean, which will then be defined with zAvg*
foreach x of local regressors{
by `panelvar', sort: egen zAvg`x' = mean(`x')
}

***4.Step
***generate yi0 (being the first value of the dependent variable for each panelvar):
foreach x of local regressand {
by `panelvar': generate yi0 = `regressand'[1]
}

***5.Step
***Program for random sampling

local n 1  // shows the number of replications

forvalues i= 1(1) `n' {
local n = `n'+1

preserve  
            
bsample, cluster (`panelvar') idcluster(newpanelvar)

tokenize `varlist'
local regressand `1'

xttobit `regressand' lag* `regressors' zAvg* yi0 , intm(gh) ll(0) ul(1)
restore
}


end

**************************************************************
-- 
GMX DSL: Internet-, Telefon- und Handy-Flat ab 19,99 EUR/mtl.  
Bis zu 150 EUR Startguthaben inklusive! http://portal.gmx.net/de/go/dsl
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index