Announcement

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

  • Scatterplot of dates?

    Hi All,

    I'm using STATA 15.

    My question is how do I convert and then format a datetime variable (current type: double, format: %tc) properly so I can create a scatterplot where both axes show certain mm/yy?

    My code is below. Please let me know if I can provide better/additional info! Thank you so much

    Code:
    format firstr_birth %td
    format secondr_birth %td
    graph twoway scatter secondr_birth firstr_birth, ///
    legend(off) mcolor(black) ///
    ytitle("Date of first live birth during follow-up round") ///
    xtitle("Date of first live birth at baseline")  ///
    title("Plot of dates of first live birth as reported during baseline & follow-up rounds", color(black)) ///  
    graphregion(color(white)) ylabel(, grid glcolor(gs14))
    My graph currently looks like the below
    Attached Files

  • #2
    Does this give you what you want?
    Code:
    format firstr_birth secondr_birth %tdNN/YY
    By the way, I found that by typing help format, and then clicking on [D] datetime display formats.

    HTH.
    --
    Bruce Weaver
    Email: bweaver@lakeheadu.ca
    Web: http://sites.google.com/a/lakeheadu.ca/bweaver/
    Stata version: 15.1 IC (Windows)

    Comment


    • #3
      Sorry, but Bruce's advice is on this occasion not obviously going to solve the problem. The variables

      Code:
       secondr_birth firstr_birth
      are implied to be date-times in milliseconds from the start of 1 January 1960. If that is not so, why do they have a date display format %tc assigned?

      All we can see is a value 2.15 billion but even that is only a date-time within January 1960.

      So you need to convert them to monthly dates to get anywhere. You can't do that by assigning them a different display format.

      Let's make this concrete. As I write it is 17:39 in my time zone. That is getting for 2 trilllion milliseconds since the start of 1 January 1960. And I do mean trillion.

      Code:
      . di %13.0f clock("2019 Jan 11 17:39", "YMD hm")
      1862847540000
      If you now assign that variable a daily date display format, you are telling Stata "I really have daily dates in that variable".

      So, it can try to interpret them as daily dates 2 trillion days after the start of 1960, modulo a hundred or two billion.

      I am not clear that your data are in good shape, but I doubt that is what you need.

      Please start again, read and act on FAQ Advice #12

      https://www.statalist.org/forums/help#stata

      -- and give us a data example using dataex (and swing by #18 on your way back).

      On the information you've given you need to push your date-times through mofd(dofc()) -- but I would like to see a data example to be sure.

      Comment

      Working...
      X