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]

Re: st: fill or expand data


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: fill or expand data
Date   Tue, 12 Oct 2010 20:43:22 +0000

<>

Be sure to show us what you've tried.   I don't think -tsfill- can be used to get the target dataset you describe.

Here's one way to get your target dataset:

***********************!
//input your dataset//
clear
inp id  str14(yearenter   yearexit)    yearcont
1  "10/80"             "2/81"           81
1  "3/81"                "4/81"          81
1 "11/85"             "2/87"          87
end

//first, put your dates into a format stata understands//
ds yeare*
foreach x in `r(varlist)' {
g `x'2 = date(`x', "M19Y")
format `x'2 %tdMon_CCYY
}


//create range of years and reshape//
g range = ""
forval n = 1/`=_N' {
	local start = year(yearenter2) in `n'
	local stop = year(yearexit2) in `n'
	di "`start' to `stop'"
	numlist "`start'(1)`stop'"
	replace range = "`r(numlist)'" in `n'
	}
split range, p(" ")
drop range yearenter yearexit
g i = _n
reshape long range, i(i) j(obs)
drop i
drop if mi(range)
l

***********************!

- Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
Fax: +979.845.0249
http://ppri.tamu.edu


On Oct 12, 2010, at 12:16 PM, <[email protected]>
 wrote:

> Dear Statalist,
> My question is about to display or fill my data set. I have tried the
> command tsfill but I don't know how  continue to arrive at my final
> data set.
> I have  this data:
> id  year enter   year exit    yearcont
> 1  10/80             2/81           81
> 1  3/81                4/81          81
> 1 11/85             2/87          87
> 
> And I want to have this one
> 
> id  year enter   year exit    yearcont
> 1  10/80               3/81           80
> 1   10/80              3/81            81
> 1   3/81               4/81             81
> 1   11/85             2/87             85
> 1    11/85            2/87            86
> 1  11/85             2/87              87
> 
> Thanks for your help.
> Catia
> 
> *
> *   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/




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