Statalist The Stata Listserver


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

st: RE: extract rows from panel dataset


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: extract rows from panel dataset
Date   Sun, 10 Sep 2006 16:06:04 -0500

I don't understand why you cannot use -if- restrictions and what timex,
timey, and timez represent; however, at least in the simpler example this
seems to accomplish the task:

program foo , rclase
  version 9.2
  syntax varlist(ts min=2 numeric) , Timex(numlist >=0 integer)
Units(numlist integer)
  qui tsset
  local tvar `r(timevar)'
  local pvar "`r(panelvar)'"
  local tx: subinstr local timex " " ",", all
  local u: subinstr local units " " ",", all
  tempvar yx foo
  gen `foo' = 1 if  inlist(`tvar',`tx') & inlist(`pvar', `u')
  qui mkmat `pvar' `tvar' `varlist' if `foo' == 1, matrix(`yx')
  matrix list `yx'
end


Which results in:

. webuse invest2,clear

. tsset com time
       panel variable:  company (strongly balanced)
        time variable:  time, 1 to 20

. foo invest market stock, timex(3 6 7 9) units(1 2 4)
(88 missing values generated)

__000000[12,5]
       company       time     invest     market      stock
 r1          1          3  410.60001  5387.1001  156.89999
 r2          1          6  461.20001  4643.8999      207.2
 r3          1          7        512  4551.2002      255.2
 r4          1          9  499.60001     4053.7  264.10001
 r5          2          3  66.260002  883.90002  34.700001
 r6          2          6  69.410004  727.79999  67.099998
 r7          2          7  68.349998  643.59998  75.199997
 r8          2          9  47.400002  588.40002  67.099998
 r9          4          3  35.049999        729  7.4000001
r10          4          6      28.57      628.5       26.5
r11          4          7  48.509998  537.09998  36.200001
r12          4          9      37.02  617.20001  84.400002

Scott


> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Tom Boonen
> Sent: Sunday, September 10, 2006 9:25 AM
> To: [email protected]
> Subject: st: extract rows from panel dataset
> 
> 
> Now my question: How can I extract from the varlist (i.e. the matrix
> YX) only those rows that the user specified in timex() and units().
> 


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