I've written a function that, among other things, plots a date fixed effect coefficient's value across the date. I intend for this function to be agnostic to date format, so I've written it to extract the date variable's format, then specify that format in the plotting code. Here is the code I use:
This code works and generates a plot with the data set I'm using, for which `varlist' is a monthly date variable in %tm format. However, the plot displays the x-axis labels as numbers, rather than in %tm. I tested the function with "%tm" in the place of `dtype' and it works. I've also double-checked that the `varlist' variable is in %tm format with a
command inside the function. It prints "%tm".
Is it possible to use this approach within a .ado file? If so, what am I doing wrong here? I've tried using quotes around the relevant macros, and that doesn't work, either.
HTML Code:
syntax varlist(max=1) [using/] [, /// MATname(string) /// Name of matrix to save results in; default=M INDEXname(string) /// Name of the index to be generated noBOUNDS /// Optionally suppress upper/lower bounds noPLOT /// If specified, no plot will be generated PTitle(string) /// Title of plot in price index plot PSave(string) /// Option to save plot, supplying name and filepath PTICKs(real 0) /// Option to specify ticks in the plot ] ... // determine date variable type loc dtype `: format `varlist'' loc odate : di `dtype' `odate' // if specified, set axis labels if (`pticks' != 0){ qui sum `varlist' if ~missing(`indexname') loc xlab `=r(min)'(`pticks')`r(max)' } // generate plot //di "`dtype'" line `indexname' `varlist' if ~missing(`varlist'), /// xlab(`xlab', format(`dtype') angle(45)) xtitle("") /// ylab(, angle(horizontal)) graphregion(color(white)) /// note("Omitted date: `odate'") /// ytitle("") title(`ptitle') name(`depvar', replace)
HTML Code:
display "`: format `varlist''"
Is it possible to use this approach within a .ado file? If so, what am I doing wrong here? I've tried using quotes around the relevant macros, and that doesn't work, either.
Comment