I have the following data:
The variables denoted dtt are dates - that is, the number after dtt is a date in Stata format.
What I would like to do is label each variable in a human-readable format using that number.
I can format the relevant substring extracted from the variable name to display it correctly as a date, but I can't figure out how to save it as a correctly formatted date string. I can't format a local variable, otherwise I would do that.
I cannot do
, since that inserts the string "%td" after the number `day', though that is also something akin to what I want to do.
Thanks for your help!
Code:
clear input float(id dtt20195 dtt20196 dtt20197 dtt20198 dtt20199 dtt20200 dtt20201 dtt20202 dtt20203 dtt20204 dtt20205 dtt20206 dtt20207 dtt20208 dtt20209 dtt20210 dtt20211 dtt20212 dtt20213 dtt20214 year) 0 0 5 8 12 14 18 25 31 32 39 39 34 26 23 19 13 11 9 5 2 1 1 5 8 10 11 17 21 25 29 32 34 34 30 28 25 21 19 17 15 10 5 1 2 2 4 8 12 16 18 19 22 24 27 27 24 20 18 17 15 13 12 6 4 1 end
What I would like to do is label each variable in a human-readable format using that number.
I can format the relevant substring extracted from the variable name to display it correctly as a date, but I can't figure out how to save it as a correctly formatted date string. I can't format a local variable, otherwise I would do that.
Code:
foreach vl of varlist dtt* { local day = substr("`vl'", 4, .) * The following line will display the correctly formatted date, e.g., 17apr2015 di %td `day' * Here I would like to label using the date label variable `vl' " (correctly formatted day) " }
Code:
label variable `vl' " `day' %td"
Thanks for your help!
Comment