Hi,

My objective is to create separate excel files for each potential value of a string variable called ownershipdate_IPO. To do this I created a group variable named temp_id and made a loop that runs through each potential value of the temp ID. However, in the name of the excel file I want to include the label and not the value of the temp ID. To do this I used `: var label `i'' in the excel file name, but for each cycle of the loop I get an error the includes the temp_id and then "invalid file name" (f.eg. "42 invalid file name"). I assume that the mistake relates to the truncation marks in the export excel line, but can not figure out what it exactly is.


Code:
 
replace ownershipdate_IPO = subinstr(ownershipdate_IPO, "/", "_",.)
egen temp_id = group(ownershipdate_IPO), label
su temp_id, meanonly
forvalues i = 1/`r(max)' {
 export excel using "G:ownershipinput_IPO_`: var label `i''.xls" if temp_id == `i', firstrow(variables) replace
 }
Regards