What is wrong with the green font line of code in the program below? It throws a 198 error: invalid '1'. However when I change the line to save project`2', replace after setting a directory for the do file, it runs perfectly. But I need to add another path when saving within the program. I've tried double quotes but it does not work. Thank you.
capture program drop closed2020
program define closed2020
clear
use "C:\Documents\Stata Code Output\dataset_a"
encode projectid, gen(`1')
keep if `1'==`2'
set obs `=_N+1'
foreach var in a b c d e {
replace `var' = `var'[_n-1] if `1'==.
}
save "C:\Documents\project`"`2'"", replace
end
closed2020 pid2 1
closed2020 pid2 2
closed2020 pid2 3
closed2020 pid2 4
closed2020 pid2 5
closed2020 pid2 6
closed2020 pid2 7
closed2020 pid2 8
closed2020 pid2 9
closed2020 pid2 10
capture program drop closed2020
program define closed2020
clear
use "C:\Documents\Stata Code Output\dataset_a"
encode projectid, gen(`1')
keep if `1'==`2'
set obs `=_N+1'
foreach var in a b c d e {
replace `var' = `var'[_n-1] if `1'==.
}
save "C:\Documents\project`"`2'"", replace
end
closed2020 pid2 1
closed2020 pid2 2
closed2020 pid2 3
closed2020 pid2 4
closed2020 pid2 5
closed2020 pid2 6
closed2020 pid2 7
closed2020 pid2 8
closed2020 pid2 9
closed2020 pid2 10

Comment