Statalist


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

Re: st: xtserial


From   "Koksal, Bulent" <bkoksal@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: xtserial
Date   Tue, 12 Feb 2008 09:28:06 +0200

I pasted the outcome below. I am using Stata/SE 10.

In the following regression, region, and year are the cross section
and time variables respectively.



--------
. xtreg  y ylag g int99 int02 int_07, fe
(results omitted)
. xtserial  y ylag g int99 int02 int_07
---------------------------------------------------------------------------------------------------------
begin xtserial ---
- version 8.0
- syntax varlist [if] [in], [ Output ]
- marksample touse
- qui tsset
  ----------------------------------------------------------------------------------------------------------
begin tsset ---
  - version 10
  - if `"`0'"' == "" {
  = if `""' == "" {
  - _ts tvar pvar, panel
    ----------------------------------------------------------------------------------------------------------
begin _ts ---
    - version 6, missing
    - gettoken tok : 0, parse(" ,")
    - if "`tok'" != "," & "`tok'" != "" {
    = if "tvar" != "," & "tvar" != "" {
    - gettoken tmac 0 : 0, parse(" ,")
    - c_local `tmac' "`_dta[_TStvar]'"
    = c_local tvar "year"
    - gettoken tok : 0, parse(" ,")
    - if "`tok'" != "," & "`tok'" != "" {
    = if "pvar" != "," & "pvar" != "" {
    - gettoken pmac 0 : 0, parse(" ,")
    - c_local `pmac' "`_dta[_TSpanel]'"
    = c_local pvar "region"
    - }
    - }
    - syntax [if] [in] [, Sort Panel Onepanel]
    - if "`_dta[_TStvar]'" == "" {
    = if "year" == "" {
      di in red "time variable not set, use -tsset varname ...-"
      exit 111
      }
    - if "`_dta[_TSpanel]'"!="" & "`panel'"=="" & "`onepanel'"=="" {
    = if "region"!="" & "panel"=="" & ""=="" {
      di in red "command may not be used with panel data"
      exit 459
      }
    - if "`sort'"!="" {
    = if ""!="" {
      qui sort `_dta[_TSpanel]' `_dta[_TStvar]'
      }
    - if "`_dta[_TSpanel]'"!="" & "`panel'"=="" & "`onepanel'"!="" {
    = if "region"!="" & "panel"=="" & ""!="" {
      sum `_dta[_TSpanel]' `if' `in' , meanonly
      if r(min) != r(max) {
      di in red "sample may not include multiple panels"
      exit 459
      }
      }
    ------------------------------------------------------------------------------------------------------------
end _ts ---
  - local fmt: format `tvar'
  = local fmt: format year
  - local tsdelta : char _dta[_TSdelta]
  - if "`tsdelta'" == "" {
  = if "+1.0000000000000X+000" == "" {
    local tsdelta 1
    }
  - tsset `pvar' `tvar', format(`fmt') delta((`tsdelta'))
  = tsset region year, format(%9.0g) delta((+1.0000000000000X+000))
    --------------------------------------------------------------------------------------------------------
begin tsset ---
    - version 10
    - if `"`0'"' == "" {
    = if `"region year, format(%9.0g) delta((+1.0000000000000X+000))"' == "" {
      _ts tvar pvar, panel
      local fmt: format `tvar'
      local tsdelta : char _dta[_TSdelta]
      if "`tsdelta'" == "" {
      local tsdelta 1
      }
      tsset `pvar' `tvar', format(`fmt') delta((`tsdelta'))
      ret add
      exit
      }
    - syntax [varlist(numeric max=2 default=none)] [, CLEAR Daily
Format(passthru) Generic Halfyearly Monthly Quarterly Week
> ly Yearly DELta(string) Clocktime FORCE ]
    - if "`clear'" != "" {
    = if "" != "" {
      syntax [, CLEAR]
      Clear
      exit
      }
    - if "`varlist'"=="" {
    = if "region year"=="" {
      _ts tvar pvar, panel
      tsset `pvar' `tvar', `daily' `format' `generic' `halfyearly'
`monthly' `quarterly' `weekly' `yearly' `clocktime'
      ret add
      exit
      }
    - syntax varlist(numeric max=2 default=none) [ , CLEAR Daily
Format(string) Generic Halfyearly Monthly Quarterly Weekly
> Yearly DELta(string) Clocktime FORCE ]
    - local ct : word count `varlist'
    = local ct : word count region year
    - if `ct'==2 {
    = if 2==2 {
    - tokenize `varlist'
    = tokenize region year
    - local panel `1'
    = local panel region
    - local timevar `2'
    = local timevar year
    - }
    - else {
      local timevar `varlist'
      }
    - local period `daily' `weekly' `monthly' `quarterly' `halfyearly'
`yearly' `generic' `clocktime'
    = local period
    - if `"`format'"'!="" {
    = if `"%9.0g"'!="" {
    - local dfltfmt "no"
    - if "`period'" != "" {
    = if "" != "" {
      di in red "may not specify both format() and `period'"
      exit 198
      }
    - local try : di `format' 2
    = local try : di %9.0g 2
    - }
    - else if "`period'" != "" {
    = else if "" != "" {
      local ct : word count `period'
      if `ct' > 1 {
      di in red "may only specify one time-scale from " "daily,
weekly, monthly, "
      di in red "quarterly, halfyearly, yearly, and generic"
      exit 198
      }
      local curfmt : format `timevar'
      local fmttype = substr("`curfmt'", 2, 1)
      if "`fmttype'" != "d" & "`fmttype'" != "t" {
      local format = "%t" + substr("`period'",1,1)
      if substr("`period'", 1, 1) == "c" {
      local dfltfmt "yes"
      }
      }
      else {
      local format `curfmt'
      }
      }
    - else {
      local format : format `timevar'
      }
    - capture assert int(`timevar')==`timevar'
    = capture assert int(year)==year
    - if _rc {
      di in red "time variable must contain only integer values"
      exit 451
      }
    - sort `panel' `timevar'
    = sort region year
    - if "`panel'" != "" {
    = if "region" != "" {
    - local bypfx "by `panel': "
    = local bypfx "by region: "
    - }
    - if `"`format'"' != "" {
    = if `"%9.0g"' != "" {
    - format `timevar' `format'
    = format year %9.0g
    - }
    - tempname scdelta
    - mata: _TS_p_delta("`scdelta'", "`delta'", "`timevar'")
    = mata: _TS_p_delta("__000001", "(+1.0000000000000X+000)", "year")
    - if `scdelta' == -2 {
    = if __000001 == -2 {
      di as err "invalid time-series format on `timevar'"
      exit 120
      }
    - if `scdelta' == -1 {
    = if __000001 == -1 {
      di as err "invalid argument in delta()"
      exit 198
      }
    - tempvar timedif
    - qui `bypfx' gen double `timedif' = `timevar'[_n+1] - `timevar'
    = qui by region:  gen double __000003 = year[_n+1] - year
    - qui sum `timedif', meanonly
    = qui sum __000003, meanonly
    - if r(min) == 0 {
      if "`panel'" != "" {
      di in red "repeated time values within panel"
      }
      else {
      di in red "repeated time values in sample"
      }
      exit 451
      }
    - if "`force'" == "" {
    = if "" == "" {
    - if r(min) < `scdelta' {
    = if r(min) < __000001 {
      di in red "time values with period less than delta() found"
      exit 451
      }
    - }
    - Clear
      ------------------------------------------------------------------------------------------------
begin tsset.Clear ---
      - char _dta[_TStvar]
      - char _dta[_TSpanel]
      - char _dta[_TSdelta]
      - char _dta[_TSitrvl]
      - char _dta[tis]
      - char _dta[iis]
      --------------------------------------------------------------------------------------------------
end tsset.Clear ---
    - nobreak {
    - char _dta[_TStvar] "`timevar'"
    = char _dta[_TStvar] "year"
    - char _dta[_TSpanel] "`panel'"
    = char _dta[_TSpanel] "region"
    - char _dta[_TSdelta] `: di %21x `scdelta''
    = char _dta[_TSdelta] +1.0000000000000X+000
    - char _dta[_TSitrvl] 1
    - char _dta[tis] "`timevar'"
    = char _dta[tis] "year"
    - char _dta[iis] "`panel'"
    = char _dta[iis] "region"
    - }
    - if "`dfltfmt'" == "yes" & substr("`format'", 3, 1) == "c" {
    = if "no" == "yes" & substr("%9.0g", 3, 1) == "c" {
      format `timevar' %tcDDmonCCYY_HH:MM:SS.sss
      }
    - Query
      ------------------------------------------------------------------------------------------------
begin tsset.Query ---
      - local timevar `_dta[_TStvar]'
      = local timevar year
      - local panel `_dta[_TSpanel]'
      = local panel region
      - local delta : char _dta[_TSdelta]
      - if "`panel'" == "" {
      = if "region" == "" {
        qui count if `timevar' - `timevar'[_n-1] != `delta' &
`timevar' != . in 2/l
        local gaps = r(N)
        }
      - else {
      - qui count if `timevar' - `timevar'[_n-1] != `delta' &
`timevar' != . & `panel' == `panel'[_n-1] in 2/l
      = qui count if year - year[_n-1] != +1.0000000000000X+000 & year
!= . & region == region[_n-1] in 2/l
      - local gaps = r(N)
      - }
      - if "`panel'" == "" {
      = if "region" == "" {
        tempvar seenvar
        local t0 = `timevar'[1]
        gen long `seenvar' = sum(`timevar' != .)
        local t1 = `timevar'[`seenvar'[_N]]
        }
      - else {
      - tempname firstob lastob
      - qui gen byte `firstob' = `panel' != . & `panel' != `panel'[_n-1]
      = qui gen byte __000004 = region != . & region != region[_n-1]
      - qui sum `timevar' if `firstob', meanonly
      = qui sum year if __000004, meanonly
      - local t0 = r(min)
      - qui gen byte `lastob' = `panel' != . & `timevar' != . &
(`panel' != `panel'[_n+1] | `timevar'[_n+1] == .)
      = qui gen byte __000005 = region != . & year != . & (region !=
region[_n+1] | year[_n+1] == .)
      - qui sum `timevar' if `lastob', meanonly
      = qui sum year if __000005, meanonly
      - local t1 = r(max)
      - local npanel = r(N)
      - sum `panel', meanonly
      = sum region, meanonly
      - ret scalar imin = r(min)
      - ret scalar imax = r(max)
      - tempvar tmin tmax tcount
      - qui by `panel' : gen double `tcount' = _N if !missing(`timevar')
      = qui by region : gen double __000008 = _N if !missing(year)
      - capture assert `tcount' == `tcount'[1]
      = capture assert __000008 == __000008[1]
      - if c(rc) {
        local bal unbalanced
        }
      - else {
      - CheckStrongBal `npanel' `panel' `timevar'
      = CheckStrongBal 81 region year
        -------------------------------------------------------------------------------------
begin tsset.CheckStrongBal ---
        - args npanel panel time
        - capture bysort `time': assert `npanel' == _N
        = capture bysort year: assert 81 == _N
        - return scalar rc = c(rc)
        ---------------------------------------------------------------------------------------
end tsset.CheckStrongBal ---
      - if r(rc) {
        local bal "weakly balanced"
        }
      - else {
      - local bal "strongly balanced"
      - }
      - }
      - di in gr _col(8) "panel variable:  " in ye "`panel' (`bal')"
      = di in gr _col(8) "panel variable:  " in ye "region (strongly balanced)"
      - return local balanced "`bal'"
      = return local balanced "strongly balanced"
      - }
      - local fmt : format `timevar'
      = local fmt : format year
      - local t0s = trim(string(`t0', "`fmt'"))
      = local t0s = trim(string(1987, "%9.0g"))
      - local t1s = trim(string(`t1', "`fmt'"))
      = local t1s = trim(string(2007, "%9.0g"))
      - di in gr _col(9) "time variable:  " _c
      - local i 1
      - local line`i' `=abbrev("`timevar'",13)',
      = local line1 year,
      - local linelen = length(`"`line`i''"')
      = local linelen = length(`"year,"')
      - if (`linelen' + length(`"`t0s'"')) < 53 {
      = if (5 + length(`"1987"')) < 53 {
      - local line`i' `line`i'' `t0s'
      = local line1 year, 1987
      - local linelen = length(`"`line`i''"')
      = local linelen = length(`"year, 1987"')
      - }
      - else {
        local `++i'
        local line`i' `t0s'
        local linelen = length(`"`line`i''"')
        }
      - if (`linelen' + 3) < 53 {
      = if (10 + 3) < 53 {
      - local line`i' `"`line`i'' to"'
      = local line1 `"year, 1987 to"'
      - local linelen = length(`"`line`i''"')
      = local linelen = length(`"year, 1987 to"')
      - }
      - else {
        local `++i'
        local line`i' "to"
        local linelen = 3
        }
      - if (`linelen' + length(`"`t1s'"')) < 53 {
      = if (13 + length(`"2007"')) < 53 {
      - local line`i' `line`i'' `t1s'
      = local line1 year, 1987 to 2007
      - local linelen = length(`"`line`i''"')
      = local linelen = length(`"year, 1987 to 2007"')
      - }
      - else {
        local `++i'
        local line`i' `t1s'
        local linelen = length(`"`t1s'"')
        }
      - if `gaps' > 0 {
      = if 405 > 0 {
      - if `gaps' == 1 {
      = if 405 == 1 {
        local note "but with a gap"
        }
      - else {
      - local note "but with gaps"
      - }
      - if (`linelen' + length(`", `note'"')) < 53 {
      = if (18 + length(`", but with gaps"')) < 53 {
      - local line`i' `line`i'', `note'
      = local line1 year, 1987 to 2007, but with gaps
      - }
      - else {
        local `++i'
        local line`i' `note'
        }
      - }
      - forvalues j = 1/`i' {
      = forvalues j = 1/1 {
      - di in ye _col(25) `"`line`j''"'
      = di in ye _col(25) `"year, 1987 to 2007, but with gaps"'
      - }
      - tempname fancyd
      - mata:_TS_p_delta2str("`fancyd'", `=`delta'', "`timevar'")
      = mata:_TS_p_delta2str("__000009", 1, "year")
      - di in gr _col(17) "delta:  " in ye "`=`fancyd''"
      = di in gr _col(17) "delta:  " in ye "1 unit"
      - ret scalar tmin = `t0'
      = ret scalar tmin = 1987
      - ret scalar tmax = `t1'
      = ret scalar tmax = 2007
      - ret scalar tdelta = `delta'
      = ret scalar tdelta = +1.0000000000000X+000
      - ret local tmins `t0s'
      = ret local tmins 1987
      - ret local tmaxs `t1s'
      = ret local tmaxs 2007
      - ret local tdeltas "`=`fancyd''"
      = ret local tdeltas "1 unit"
      --------------------------------------------------------------------------------------------------
end tsset.Query ---
    - if "`dfltfmt'" == "yes" & substr("`format'", 3, 1) == "c" {
    = if "no" == "yes" & substr("%9.0g", 3, 1) == "c" {
      format `timevar' %tc
      }
    - ret add
    - local fmt : format `timevar'
    = local fmt : format year
    - return local tsfmt `fmt'
    = return local tsfmt %9.0g
    - return local unit1 = substr("`fmt'", 3, 1)
    = return local unit1 = substr("%9.0g", 3, 1)
    - Period per : "`period'" `return(unit1)'
    = Period per : "" .
      -----------------------------------------------------------------------------------------------
begin tsset.Period ---
      - args newper colon per unit1
      - if "`per'" == "" {
      = if "" == "" {
      - if "`unit1'" != "" {
      = if "." != "" {
      - local c "clocktime"
      - local g "generic"
      - local d "daily"
      - local w "weekly"
      - local m "monthly"
      - local q "quarterly"
      - local h "halfyearly"
      - local y "yearly"
      - capture c_local `newper' ``unit1''
      = capture c_local per
      - }
      - else {
        c_local `newper' "generic"
        }
      - }
      - else {
        c_local `newper' `per'
        }
      -------------------------------------------------------------------------------------------------
end tsset.Period ---
    - return local unit `per'
    = return local unit
    - ret local timevar "`timevar'"
    = ret local timevar "year"
    - ret local panelvar "`panel'"
    = ret local panelvar "region"
    ----------------------------------------------------------------------------------------------------------
end tsset ---
  - ret add
  - exit
  ------------------------------------------------------------------------------------------------------------
end tsset ---
- local ivar "`r(panelvar)'"
= local ivar "region"
- if "`ivar'" == "" {
= if "region" == "" {
  di as err "panel variable not specified"
  exit 498
  }
- local tvar "`r(timevar)'"
= local tvar "year"
- if "`tvar'" == "" {
= if "year" == "" {
  di as err "time variable not specified"
  exit 498
  }
- if "`output'" == "" {
= if "" == "" {
- local qui quietly
- }
- `qui' regress d.(`varlist') if `touse', nocons cluster(`ivar')
= quietly regress d.(y ylag g int99 int02 int_07) if __000000, nocons
cluster(region)
  --------------------------------------------------------------------------------------------------------
begin regress ---
  - version 9, missing
  - local version : di "version " string(_caller()) ", missing :"
  - if _by() {
    local BY `"by `_byvars'`_byrc0':"'
    }
  - syntax [anything] [if] [in] [aw fw iw pw] [, VCE(passthru) Robust
CLuster(passthru) * ]
  - if `:length local vce' {
  = if 0 {
    `version' `BY' _vce_parserun regress, mark(CLuster) eq(NOConstant) : `0'
    if "`s(exit)'" != "" {
    ereturn local cmdline `"regress `0'"'
    exit
    }
    _vce_parse, argopt(CLuster) opt(OLS Robust HC2 HC3) old :
[`weight'`exp'], `vce' `robust' `cluster'
    if "`r(cluster)'" != "" {
    local cluster cluster(`r(cluster)')
    }
    else if "`r(vce)'" != "ols" {
    local robust = "`r(vce)'"
    }
    local vce = cond("`r(vce)'" != "", "`r(vce)'", "ols")
    }
  - else if "`cluster'" != "" {
  = else if "cluster(region)" != "" {
  - local vce cluster
  - }
  - else if "`weight'" == "pweight" | "`robust'" != "" {
  = else if "" == "pweight" | "" != "" {
    local vce robust
    }
  - else local vce ols
  - if replay() {
    if _by() {
    error 190
    }
    `version' Display `0'
    exit
    }
  - `version' `BY' _regress `anything' `if' `in' [`weight'`exp'],
`options' `robust' `cluster'
  = version 8, missing :  _regress d.(y ylag g int99 int02 int_07) if
__000000  [], nocons  cluster(region)
no observations
  ----------------------------------------------------------------------------------------------------------
end regress ---
-----------------------------------------------------------------------------------------------------------
end xtserial ---
r(2000);


On Feb 11, 2008 2:06 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> Put
>
> . set trace on
>
> Before you call to -xtserial- to see where it is crashing.
>
> Koksal, Bulent
>
>
> I made  a mistake. Sorry.
>
> .xtreg y x1 x2, fe
>
> works fine. but I get the "no obs" message for the following
>
> .xtserial y x1 x2
> no observations
> r(2000);
>
>
> On Feb 10, 2008 9:17 PM,  <nicola.baldini2@unibo.it> wrote:
> > Did you tell us EXACTLY what you type?
> > I type -xtserial- (please cite that it's from SJ) and I get
> > varlist required
> > r(100);
> > which suggests the solution
> > Nicola
> >
> >
> > At 02.33 10/02/2008 -0500, "Koksal, Bulent" wrote:
> > >Dear Stata users,
> > >
> > >I estimate a fe panel model
> > >
> > >.xtreg y x1 x2, fe
> > >
> > >and everything works fine. then I want to test for correlation by
> > >
> > >.xtserial
> > >
> > >but I get
> > >
> > >no observations
> > >r(2000);
> > >
> > >Any suggestions?
>
>
> *
> *   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/
>



-- 
Bülent Köksal

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index