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: Creating a series with two observations for each month


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Creating a series with two observations for each month
Date   Mon, 4 Nov 2013 02:19:24 +0000

Don't plot against the -tsset- time variable. Plot against your real
date variable.
Nick
[email protected]


On 4 November 2013 01:45, Pedro Nakashima <[email protected]> wrote:
> Do you know how to use date variable values as labels in time axis?
> (considering that time variable is seq)
>
> Thank you for the answer.
>
>
> 2013/11/3 Nick Cox <[email protected]>:
>> The only way I know to do this satisfactorily is to -tsset- in terms
>> of some sequence number and have a separate date variable for plotting
>> etc. Clearly you are working with a fiction that the dates are equally
>> spaced.
>>
>> Here is a token example.
>>
>> . clear
>>
>> . set obs 12
>> obs was 0, now 12
>>
>> . gen month = _n
>>
>> . gen year = 2012
>>
>> . expand 2
>> (12 observations created)
>>
>> . sort month
>>
>> . gen day = cond(mod(_n, 2), 1, 15)
>>
>> . gen date = mdy(month, day, year)
>>
>> . format date %td
>>
>> . gen seq = _n
>>
>> . tsset seq
>>         time variable:  seq, 1 to 24
>>                 delta:  1 unit
>> . list
>>
>>      +--------------------------------------+
>>      | month   year   day        date   seq |
>>      |--------------------------------------|
>>   1. |     1   2012     1   01jan2012     1 |
>>   2. |     1   2012    15   15jan2012     2 |
>>   3. |     2   2012     1   01feb2012     3 |
>>   4. |     2   2012    15   15feb2012     4 |
>>   5. |     3   2012     1   01mar2012     5 |
>>      |--------------------------------------|
>>   6. |     3   2012    15   15mar2012     6 |
>>   7. |     4   2012     1   01apr2012     7 |
>>   8. |     4   2012    15   15apr2012     8 |
>>   9. |     5   2012     1   01may2012     9 |
>>  10. |     5   2012    15   15may2012    10 |
>>      |--------------------------------------|
>>  11. |     6   2012     1   01jun2012    11 |
>>  12. |     6   2012    15   15jun2012    12 |
>>  13. |     7   2012     1   01jul2012    13 |
>>  14. |     7   2012    15   15jul2012    14 |
>>  15. |     8   2012     1   01aug2012    15 |
>>      |--------------------------------------|
>>  16. |     8   2012    15   15aug2012    16 |
>>  17. |     9   2012     1   01sep2012    17 |
>>  18. |     9   2012    15   15sep2012    18 |
>>  19. |    10   2012     1   01oct2012    19 |
>>  20. |    10   2012    15   15oct2012    20 |
>>      |--------------------------------------|
>>  21. |    11   2012     1   01nov2012    21 |
>>  22. |    11   2012    15   15nov2012    22 |
>>  23. |    12   2012     1   01dec2012    23 |
>>  24. |    12   2012    15   15dec2012    24 |
>>      +--------------------------------------+
>> Nick
>> [email protected]
>>
>>
>> On 4 November 2013 00:34, Pedro Nakashima <[email protected]> wrote:
>>> Dear statalisters
>>>
>>> I would like to construct a time series which is based in the following pattern:
>>>
>>> For every month, there are two observations, relative to days 1 and 15.
>>>
>>> After that, I would like to plot this series.
>>>
>>> I've tried creating date format together with "tsset td, delta(15)",
>>> but due to month length differences, this combination is creating gaps
>>> in the series.
>>>
>>> Does anyone know how to solve this problem?
>>>
>>> Thank you very much,
>>> Pedro Nakashima.
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index