Announcement

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

  • X axis scale

    Hello,

    I am trying to create a graph that looks similar to the attached:
    the code is
    twoway scatteri 0 201308 2000000000 201308 2000000000 201506 0 201506, recast(area) color(gs12) || scatteri 0 201801 2000000000 201801 2000000000 201803 0 201803, recast(area) color(gs12) || line gsp ym if importer == "US" , ytitle(U.S. Imports under GSP Program) legend(order(1 "Expirations") pos(11)) ylabel(#5) xtitle(Year&Month) subtitle(U.S. Imports under GSP Program)

    However, there is a problem because I think STATA is counting ym literally by one (from 201201, 201202,... 201212, 201213 , 201214,... ), while the data only spans from 201201 to 201212, and then from 201301 to 201312, and so on. This is strange because in my dta file, the ym only has up to Decembers. (201213, 201214, 201215 etc do not exist).

    Could someone help me with how to deal with this kind of situation?

    Thanks,
    Soyoung
    Attached Files

  • #2
    Stata [not STATA please; FAQ Advice #18] really does not know that a variable with values like 201201, 201212, 201301, 201312 is meant to be a monthly date. That's a human interpretation and only such. You need to map that to a monthly date that Stata understands.

    Similarly you are asking to re-create a graph that is based on the same highly mistaken assumption: time is taking alternately long steps of 89 and 11 short steps of 1 in each year. The pattern of the graph is dominated by this mistake

    To convert a variable that is numbers like 201201, etc. to a monthly date you need for example

    Code:
    gen mdate = ym(floor(baddate/100), mod(baddate, 100)) 
    format mdate %tm 

    Comment

    Working...
    X