Announcement

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

  • Help with Foreach loops involving date variables

    Hello,

    I am using Stata15. I have several variables that indicate a start date or an end date for a particular project. They were imported into stata as string variables.

    Using just one of the variables, I was able to make this work:

    generate addstory_sdate= monthly(addstory_s, "MY", 2019)
    format addstory_sdate %tmmonthCCYY
    order addstory_sdate, after(addstory_s)

    However, when I tried to use a foreach loop to run through all of my date variables, I couldn't get it to work. I think there is a problem with the format command. This is the code I'm using:

    foreach x of varlist addstory_s addstory_c addroom_s addroom_c {
    generate `x'date = monthly(`x', "MY", 2019)
    format `x'date %tmmonthCCYY
    order `x'date, after(`x')
    }

    I would appreciate any advice or direction.

  • #2
    Jessica:
    welcome to this forum.
    Please re-post your query on the General forum, as this one is for practicing purposes only (hence most of the thread posted here are left unreplied).
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment

    Working...
    X