Statalist


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

RE: st: FW: Help with filling in dates in a dataset


From   "Ariel Linden, DrPH" <ariel.linden@gmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: FW: Help with filling in dates in a dataset
Date   Sat, 4 Apr 2009 09:06:36 -0700

Hi Martin,

Not all of your code seems to work:

This section of code works:
--------------------------------------
gen newmonths=.
tokenize `c(Months)'
forvalues i = 1/12 {
replace newmonths=  `i' if Month== "``i''" 
}

*Resulting in:

Month	Value	newmonths
January	0	1
March	4	3
April	2	4
June	3	6
------------------------------------
This section of tsfills, but the newmonths starts at month 2 instead of
month 1:
--------------------------------------------------------
tsset newmonths, monthly
tsfill 

*Resulting in:

Month	Value	newmonths
January	0	1960m2
		1960m3
March	4	1960m4
April	2	1960m5
		1960m6
June	3	1960m7
--------------------------------------------------------

This section of code ends up deleting month altogether:

forvalues i = 1/12 {
replace Month= "``i''" if newmonths== `i' 
}

*Results:
Month	Value	newmonths
	0	1960m2
		1960m3
	4	1960m4
	2	1960m5
		1960m6
	3	1960m7
---------------------------------------------------------------
Then, of course dropping newmonths takes away all measurement of time:

drop newmonths

*resulting in
Month	Value
	0
	
	4
	2
	
	3

Thanks!

Ariel

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