Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transforming a time-variable in order to apply the Tsset command and draw a time graph

    Hello Stata people;

    I'm using Stata 13.1 version, and I have this data at hand:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str7 Month float Consumer_Price_Index_France
    "2000-01" 79.19
    "2000-02" 79.29
    "2000-03" 79.66
    "2000-04" 79.66
    "2000-05" 79.83
    "2000-06" 80.03
    "2000-07" 79.89
    "2000-08" 80.04
    "2000-09" 80.45
    "2000-10" 80.36
    "2000-11" 80.54
    "2000-12"  80.5
    "2001-01" 80.15
    "2001-02" 80.37
    "2001-03" 80.73
    "2001-04" 81.12
    "2001-05" 81.63
    "2001-06" 81.68
    "2001-07"  81.5
    "2001-08"  81.5
    "2001-09" 81.65
    "2001-10" 81.71
    "2001-11" 81.48
    "2001-12" 81.57
    "2002-01" 81.96
    "2002-02" 82.05
    "2002-03"  82.4
    "2002-04" 82.73
    "2002-05" 82.83
    "2002-06" 82.82
    "2002-07" 82.81
    "2002-08"    83
    "2002-09" 83.16
    "2002-10" 83.29
    "2002-11" 83.29
    "2002-12" 83.42
    "2003-01" 83.59
    "2003-02" 84.18
    "2003-03" 84.51
    "2003-04" 84.38
    "2003-05" 84.28
    "2003-06" 84.44
    "2003-07" 84.35
    "2003-08" 84.56
    "2003-09" 84.89
    "2003-10" 85.07
    "2003-11" 85.17
    "2003-12" 85.26
    "2004-01" 85.25
    "2004-02" 85.62
    "2004-03" 85.96
    "2004-04" 86.19
    "2004-05"  86.5
    "2004-06" 86.54
    "2004-07" 86.39
    "2004-08" 86.57
    "2004-09" 86.65
    "2004-10" 86.88
    "2004-11" 86.93
    "2004-12" 87.02
    "2005-01" 86.53
    "2005-02" 87.07
    "2005-03" 87.63
    "2005-04" 87.79
    "2005-05" 87.85
    "2005-06" 87.95
    "2005-07" 87.82
    "2005-08" 88.16
    "2005-09"  88.5
    "2005-10" 88.49
    "2005-11"  88.3
    "2005-12"  88.4
    "2006-01" 88.32
    "2006-02" 88.65
    "2006-03" 88.91
    "2006-04" 89.28
    "2006-05" 89.67
    "2006-06" 89.66
    "2006-07" 89.51
    "2006-08" 89.81
    "2006-09" 89.61
    "2006-10" 89.41
    "2006-11" 89.51
    "2006-12" 89.71
    "2007-01" 89.39
    "2007-02" 89.57
    "2007-03" 89.96
    "2007-04" 90.39
    "2007-05" 90.62
    "2007-06" 90.74
    "2007-07"  90.5
    "2007-08" 90.87
    "2007-09" 90.96
    "2007-10" 91.19
    "2007-11"  91.7
    "2007-12" 92.04
    "2008-01" 91.93
    "2008-02" 92.12
    "2008-03" 92.82
    "2008-04" 93.14
    end


    As you can see, it's a monthly series starting from January 2000. I do want to transform or destring that variable in a way that makes it possible to draw a time graph.

    Any help please? With thanks

  • #2
    These problems are much easier than you seem to think.

    See now https://journals.sagepub.com/doi/pdf...6867X251341416 for a guide to the subject, including principles used over and over again in threads that you have started.

    Your top resource is the help.

    I am pretty confident that monthly() and ym() were included in Stata 13.1.

    Code:
    gen wanted = monthly(Month, "YM")
    format wanted %tm 
    
    split Month, parse("-") destring 
    gen wanted2 = ym(Month1, Month2)
    format wanted2 %tm 
    
    list in 1/12, sep(6)
    Code:
         +----------------------------------------------------------+
         |   Month   Consum~e    wanted   Month1   Month2   wanted2 |
         |----------------------------------------------------------|
      1. | 2000-01      79.19    2000m1     2000        1    2000m1 |
      2. | 2000-02      79.29    2000m2     2000        2    2000m2 |
      3. | 2000-03      79.66    2000m3     2000        3    2000m3 |
      4. | 2000-04      79.66    2000m4     2000        4    2000m4 |
      5. | 2000-05      79.83    2000m5     2000        5    2000m5 |
      6. | 2000-06      80.03    2000m6     2000        6    2000m6 |
         |----------------------------------------------------------|
      7. | 2000-07      79.89    2000m7     2000        7    2000m7 |
      8. | 2000-08      80.04    2000m8     2000        8    2000m8 |
      9. | 2000-09      80.45    2000m9     2000        9    2000m9 |
     10. | 2000-10      80.36   2000m10     2000       10   2000m10 |
     11. | 2000-11      80.54   2000m11     2000       11   2000m11 |
     12. | 2000-12       80.5   2000m12     2000       12   2000m12 |
         +----------------------------------------------------------+
    
    .

    Comment

    Working...
    X