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   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   Re: st: FW: Help with filling in dates in a dataset
Date   Sat, 4 Apr 2009 23:23:42 +0200

<>


Hmm, running the code I posted, I get exactly

 +------------------+
 |    Month   Value |
 |------------------|
 |  January       0 |
 | February       . |
 |    March       4 |
 |    April       2 |
 |      May       . |
 |------------------|
 |     June       3 |


which coincides with what you originally requested...

There is no way a -replace- "...ends up deleting month altogether". It merely substitutes one value for another. It all makes me wonder what is going on in your computer... Anything special about it that the list should know?


HTH
Martin
_______________________
----- Original Message ----- From: "Ariel Linden, DrPH" <[email protected]>
To: <[email protected]>
Sent: Saturday, April 04, 2009 6:06 PM
Subject: RE: st: FW: Help with filling in dates in a dataset


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/


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