使用putexcel在Excel中插入一个字符串

Use putexcel to insert a string in Excel

我正在尝试制作一个易于使用的 do 文件,用户可以在其中插入城镇名称 s/he 想要 summarize 然后 Stata:

我正在使用保存在本地宏中的列表,因为它与 inlist() 函数配合得很好:

clear
input Date AskingRent str10 Town
2019 12 Boston 
2019 13 Cambridge
2018 14 Boston
2018 15 Cambridge
end

local towns `" "Billerica", "Boston" "'
keep if inlist(City, `towns')
***some analysis

putexcel set "results.xlsx", modify
putexcel A1 = `towns'

我希望 Excel 文件在单元格 A1 中包含 "Billerica, Boston"。

但是,我在最后一行代码中收到错误消息:

nothing found where expression expected

以下对我有用:

clear
input foo1 str20 foo2
5 "Billerica"
6 "Boston"
7 "London"
8 "New York"
end

. local towns `" "Billerica", "Boston" "'
. keep if inlist(foo2, `towns')

. putexcel set "results.xlsx", modify
. putexcel A1 = `"`towns'"'
file results.xlsx saved