Announcement

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

  • Inversing a data set and merging a year and a month variables into one time tsset variable

    Hello Stata users;

    I'm working with this data currently;

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year str9 month float inflation
    1953 "December"    .7
    1953 "November"    .7
    1953 "October"    1.1
    1953 "September"   .7
    1953 "August"      .7
    1953 "July"        .4
    1953 "June"       1.1
    1953 "May"        1.1
    1953 "April"       .8
    1953 "March"      1.1
    1953 "February"    .8
    1953 "January"     .4
    1952 "December"    .8
    1952 "November"   1.1
    1952 "October"    1.9
    1952 "September"  2.3
    1952 "August"     3.1
    1952 "July"       3.1
    1952 "June"       2.3
    1952 "May"        1.9
    1952 "April"      2.3
    1952 "March"      1.9
    1952 "February"   2.3
    1952 "January"    4.3
    1951 "December"     6
    1951 "November"   6.9
    1951 "October"    6.5
    1951 "September"    7
    1951 "August"     6.6
    1951 "July"       7.5
    1951 "June"       8.8
    1951 "May"        9.3
    1951 "April"      9.3
    1951 "March"      9.3
    1951 "February"   9.4
    1951 "January"    8.1
    1950 "December"   5.9
    1950 "November"   3.8
    1950 "October"    3.8
    1950 "September"  2.1
    1950 "August"     2.1
    1950 "July"       1.7
    1950 "June"       -.4
    1950 "May"        -.4
    1950 "April"     -1.3
    1950 "March"      -.8
    1950 "February"  -1.3
    1950 "January"   -2.1
    1949 "December"  -2.1
    1949 "November"  -1.7
    1949 "October"   -2.9
    1949 "September" -2.4
    1949 "August"    -2.9
    1949 "July"      -2.9
    1949 "June"       -.8
    1949 "May"        -.4
    1949 "April"       .4
    1949 "March"      1.7
    1949 "February"   1.3
    1949 "January"    1.3
    1948 "December"     3
    1948 "November"   4.8
    1948 "October"    6.1
    1948 "September"  6.5
    1948 "August"     8.9
    1948 "July"       9.9
    1948 "June"       9.5
    1948 "May"        9.1
    1948 "April"      8.7
    1948 "March"      6.8
    1948 "February"   9.3
    1948 "January"   10.2
    1947 "December"   8.8
    1947 "November"   8.5
    1947 "October"   10.6
    1947 "September" 12.7
    1947 "August"    11.4
    1947 "July"      12.1
    1947 "June"      17.6
    1947 "May"       18.4
    1947 "April"       19
    1947 "March"     19.7
    1947 "February"  18.8
    1947 "January"   18.1
    1946 "December"  18.1
    1946 "November"  17.7
    1946 "October"   14.9
    1946 "September" 12.7
    1946 "August"    11.6
    1946 "July"       9.4
    1946 "June"       3.3
    1946 "May"        3.4
    1946 "April"      3.4
    1946 "March"      2.8
    1946 "February"   1.7
    1946 "January"    2.2
    1945 "December"   2.2
    1945 "November"   2.3
    1945 "October"    2.3
    1945 "September"  2.3
    end
    As you can see, it is about the monthly evolution of inflation from 1940 to 1953 (the dataex just shows a part of it). What I wanna do is:
    - First, invert the dataset so it actually starts from 1940, and not 1953
    - Merge the two variables Year and Month into one time variable that makes it possible to apply the tsset command on it and draw a time-line graph which shows the evolution of inflation by year and month

    I hope I could get some help with this.

    Thanks!

  • #2
    Code:
    gen my = month + " " + string(year)
    gen mdate = monthly(my, "MY")
    assert missing(mdate) == missing(month, year)
    format mdate %tm
    drop my
    
    tsset mdate
    
    graph twoway line inflation mdate, sort

    Comment


    • #3
      Clyde Schechter Thanks for the help! That worked

      Comment

      Working...
      X