Statalist The Stata Listserver


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

RE: st: RE: extract rows from panel dataset


From   "Scott Merryman" <smerryman@kc.rr.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: extract rows from panel dataset
Date   Sun, 10 Sep 2006 17:38:37 -0500

In this case you are giving -inlist- a list a real numbers.

In addition, by using the -numlist- command your program will be able to
accept shorthand conventions for the number lists.

For example:
.  foo invest mark, t(1/5 8 9) u(1/3 8/10)

The program will pass along the timex list of: 1, 2, 3, 4, 5, 8, 9 and the
units list of: 1, 2, 3, 8, 9, 10


program foo , rclass
  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)'"
  numlist "`timex'", sort 
  numlist "`units'", sort 
  local tx: subinstr local timex " " ",", all
  local u: subinstr local units " " ",", all
  tempvar  foo yx
  gen `foo' = 1 if  inlist(`tvar',`tx') & inlist(`pvar', `u')
  qui mkmat `pvar' `tvar' `varlist' if `foo' == 1, matrix(`yx')
  matrix list `yx'
end


Scott


> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of Tom Boonen
> Sent: Sunday, September 10, 2006 5:02 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: RE: extract rows from panel dataset
> 
> Hi Scott,
> 
> I have one more question: I don't understand why the infile() command
> works here.
> 
> Specifically in your programm the expression:
> 
> inlist(`tvar',`tx')
> 
> `tvar' is a local that contains the timevariable and tx is a list of
> strings that contain the time numbers. In the help file it says that
> infile will only work if all arguments must be reals or all must be
> strings, which does not seem to be the case here.
> 
> Can you please explain. This would be a great help for me to
> understand this potentialy powerfull command better.
> 
> Thanks!
> 
> Tom



*
*   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