0

I have 500 data files and each file has 4000 variables. The name of the variable isn't consistent across each data file. So I want to tabulate the variables that contain the word "hospital" or "medical" in them.

I am using Stata for this.

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
mgdata
  • 57
  • 5

1 Answers1

2

The commmand lookfor will look through variable names and variable labels, and isn't case sensitive. Given this toy dataset

* Example generated by -dataex-. For more info, type help dataex
clear
input str1 Hospital float(x y)
"" 1 42
end
label var x "Hospital size" 
label var y "Medical expenses" 

here are some token results:

. lookfor hospital

Variable      Storage   Display    Value
    name         type    format    label      Variable label
-----------------------------------------------------------------------------------------------------
Hospital        str1    %9s                   
x               float   %9.0g                 Hospital size

. lookfor medical

Variable      Storage   Display    Value
    name         type    format    label      Variable label
-----------------------------------------------------------------------------------------------------
y               float   %9.0g                 Medical expenses

See the help for more details on lookfor.

The official command ds will allow searches of value labels, as will the community-contributed command findname.

Nick Cox
  • 35,529
  • 6
  • 31
  • 47