Quantcast

Loop according existance of variable label

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Loop according existance of variable label

jfca283
This post has NOT been accepted by the mailing list yet.
Hi.
I'm a bit lost with this.
I try to write the label for the varx.
But in some of the databases the var label exist and in others doesn't.
I must make clear that the variable and the label share the same name.

cd C:\Users\JC\Bases\Stata\
local filelist: dir . files "*.dta"

foreach file of local filelist   {
use "`file'", clear

label drop varx
label define varx 1 "text1" 15 "text15"
label values varx varx

save "`file'", replace 
}


The exposed code does run flawless until i encounter a database with the varx not having a label. It stops my code and it says

value label varx not found

So, summarising:
Whether there is or not a label for the varx, i just want that from now on the label for the mentioned variable be as i declare in the loop and save the database.
Thanks for your replies and time.
Loading...