I have a dataset that is tsset, and I would like to use the formatted (string) value of the date variable, from one particular observation, in generating a totally new variable name. For example, if the 6th observation is 1987q3, I would like a new variable named var1987q3. Here is what I have tried
Thank you for your help.
Code:
webuse gdpoil gen var`=tq(qdate[6])' =5 // macro is blank gen var`tq(qdate[6])' =5 // macro is blank levelsof qdate if _n==6, local(a) gen var`a' = 5 // kind of works but macro resolves to the numeric date value, not the formatted date string gen mystr = string(qdate, "%tq") levelsof mystr if _n==6, local(a) gen var`a' = 5 // error message "1987q3 invalid name