Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting long file path in Stata

Tags:

stata

Assume that I have a long file path (80+ characters) from my current working folder:

use .\random_folders_name\project1\secret_data\survey_data\big_constructed_file.dta 

I am looking for a way to split it into two lines to comply with a 80-character-line standard.

I've tried

    use .\random_folders_name\project1\secret_data\survey_data///
         \big_constructed_file.dta 

and

    use ".\random_folders_name\project1\secret_data\survey_data"///
         + "\big_constructed_file.dta"

without success.

I would prefer to not change the working directory as that would make necessary to change it back.

like image 225
sindri_baldur Avatar asked Oct 26 '25 15:10

sindri_baldur


1 Answers

+ can be used for string concatenation but only within an expression to be evaluated.

This works

clear 
set obs 1 
gen whatever = "a" + "b" 

and this works

local whatever = "a"  + "b" 
di "`whatever'" 

Putting one or more parts of a string in a local macro is one way to do what you want and what I would recommend if writing within 80 characters on a line.

local dir ".\random_folders_name\project1\secret_data\survey_data\"
use "`dir'big_constructed_file.dta"

You could do this:

local name = ".\random_folders_name\project1\secret_data\survey_data" + /// 
"\big_constructed_file.dta"
use "`name'" 

That's the closest I could get to taking your approach and making it work.

On backslashes, watch out: http://www.stata-journal.com/sjpdf.html?articlenum=pr0042

like image 106
Nick Cox Avatar answered Oct 29 '25 21:10

Nick Cox