Reputation: 155
I am running into a strange problem while trying to run my code. The following is a sample of my code (Note: I am already in the main directory):
cd "C:/`mydir'" //where `mydir' is the local for the folder containing the fig folder.
use cleaned.dta, clear
local outcome drr_trtd
tempname post_handle
local postfile_varlist str12(tau_text) double(pt_est se)
postfile `post_handle' `postfile_varlist' using "fig/dta/es_M12_P11_`outcome'.dta", replace
postclose `post_handle'
use "fig/dta/es_M12_P11_`outcome'.dta", clear
The issue is that whenever I try and run this code, I get an error:
postfile `post_handle' `postfile_varlist' using "fig/dta/es_M12_P11_`outcome'.dta", replace
fig/dta/es_M12_P11_drr_trtd.dta invalid name
I assumed that this may be because of quotation marks, so I removed the quotation marks and then I get the following error:
postfile `post_handle' `postfile_varlist' using fig/dta/es_M12_P11_`outcome'.dta, replace
/ invalid name
I then tried to make the file without a file-path that is I edited the postfile command as follows:
postfile `post_handle' `postfile_varlist' using "hello.dta", replace
Now, with the quotations I get the error:
"hello.dta invalid name
Without the quotation I get the same error but with hello.dat. Am I just doing something obviously wrong here? I do not understand why I am getting this error.
New Code:
local mydir /Users/F H/Desktop/Ray/analysis
cd "C:/`mydir'/"
tempname post_handle
local postfile_varlist str12(tau_text) double(pt_est se)
pwd
postfile `post_handle' `postfile_varlist' ///
using "\fig\dta\event_study_M24_P59_sa.dta" ///
, replace
I get the error:
(note: file \fig\dta\event_study_M24_P59_sa.dta not found)
file \fig\dta\event_study_M24_P59_sa.dta could not be opened
Upvotes: 0
Views: 1465
Reputation: 37208
The following test works for me so long as I have write permission in the current directory, and not otherwise.
sysuse auto, clear
local outcome drr_trtd
tempname post_handle
local postfile_varlist str12(tau_text) double(my_price myrep)
postutil clear
postfile `post_handle' `postfile_varlist' using `outcome'.dta, replace
post `post_handle' (make[1]) (price[1]) (rep78[1])
postclose `post_handle'
use `outcome'.dta, clear
list
Upvotes: 1
Reputation: 11102
I can't seem to reproduce your error. A working example:
sysuse auto, clear
local outcome drr_trtd
tempname post_handle
local postfile_varlist str12(tau_text) double(my_price myrep)
postutil clear
postfile `post_handle' `postfile_varlist' ///
using "test/test2/resu_lts_`outcome'.dta", replace
post `post_handle' (make[1]) (price[1]) (rep78[1])
postclose `post_handle'
use "test/test2/resu_lts_`outcome'.dta", clear
list
(I've created the appropriate testing directories.)
Upvotes: 2