Announcement

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

  • putdocx with automated text in table title

    I'm working with a very large dataset over several years (3-4M for each year, 5 years of data). I'm looking to generate a report prior to merging all datasets together to check against a control table. I've developed a set of code for the report, but I'm looking for a way to auto-populate the year in each table title. I"m using the dtable command, see example here.

    Code:
    dtable i.( edu sexr married raceth age16)  ,  title("2022 Demographics")  note(Results reported as N(%) and percents)   
    putdocx collect
    What I'm looking for is some way to substitute "2022" in the above code so I can generate the correct year that corresponds with each year's data, such that 2018 is plugged in for 2018 data, without me having to go in and manually change all the tables each time I run the report do file. Any ideas or thoughts? Or do I just need to make the manual change? Or maybe there's another approach I'm not considering, like an automated header or something?

  • #2
    If each dataset has a year variable (or date variable), you could do that by holding the year in a local macro. The code below assumes that the year is unique.

    Code:
    qui levelsof year, local(year)
    dtable i.(edu sexr married raceth age16) , title("`year' Demographics") note(Results reported as N(%) and percents)
    For a date variable, you would need to pass it through some function to extract the year.

    Comment


    • #3
      Thanks! This is really helpful! Yes, year is it's own variable.

      Comment

      Working...
      X