Hi all,
I am trying to rename some dummy variables generated by -tab , gen()-. The code works as intended when used within a .do file. However, it errors out when run within an .ado file. It is not clear to me what exactly the issue is. The error message indicates that there cannot be open parentheses, but when I remove the parentheses altogether I get a different error stating that the variable name that I am attempting to rename is ambiguous... Perhaps someone smarter than me can figure this out?
I am trying to rename some dummy variables generated by -tab , gen()-. The code works as intended when used within a .do file. However, it errors out when run within an .ado file. It is not clear to me what exactly the issue is. The error message indicates that there cannot be open parentheses, but when I remove the parentheses altogether I get a different error stating that the variable name that I am attempting to rename is ambiguous... Perhaps someone smarter than me can figure this out?
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str10 shape str6 color "square" "blue" "round" "blue" "round" "red" "round" "red" "round" "blue" "round" "green" "square" "green" "square" "green" "round" "red" "round" "blue" "triangular" "yellow" "triangular" "red" end
Code:
* .do file works as expected, generating 7 categorical variables and renaming them sequentially local anything shape color local num 1 foreach i of local anything { tabulate `i', generate(_qvar) nofreq rename (_qvar*) (z#), addnumber(`num') local num = `num' + `r(r)' }
Code:
* same code produces errors when used within an .ado file capture program drop test program test, rclass version 11 syntax anything tokenize `anything' local num 1 foreach i of local anything { tabulate `i', generate(_qvar) nofreq rename (_qvar*) (z#), addnumber(`num') local num = `num' + `r(r)' } end test shape color
Comment