Stata: How to check whether a variable is string


I often find that commands don’t work, because I have forgotten the “” to denote a string or the other way around.

Thus if found this useful:

	if(substr("`: type VARIABLE'",1,3)=="str"){ 
		dis "Do something with a string variable"
		dis "Do something with a different type of variable"

This uses 1) the macro extend function:

 local locname : type VARNAME

and 2) the string function:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s