Dear Stata users,
I have a dataset with 170+ variables, and these variables indicate same information for different series. For example, variable mpg1 indicates mileage for car type A, and mpg2 indicates mileage for car type B....... However in my real dataset mpg1 is named AZ, mpg2 is named BE. My question is how can I label these variables in a cycle way? That is to say, label variable mpg1 mpg2 mpg3 mpg4 mpg5 (but named AZ BE BJ BO BT in practice) as "Mileage (mpg)". Thank you.
The following example illustrate the data structure preliminarily. And what's more, in my practical dataset, variables are named in alphabetic, i.e. A, B, C, D, E, ......, FK, FL, FM, FN, FO. So I can't label variables according to their name pattern, for example label variable mpg`n' "Mileage (mpg)" in a loop.
I have a dataset with 170+ variables, and these variables indicate same information for different series. For example, variable mpg1 indicates mileage for car type A, and mpg2 indicates mileage for car type B....... However in my real dataset mpg1 is named AZ, mpg2 is named BE. My question is how can I label these variables in a cycle way? That is to say, label variable mpg1 mpg2 mpg3 mpg4 mpg5 (but named AZ BE BJ BO BT in practice) as "Mileage (mpg)". Thank you.
The following example illustrate the data structure preliminarily. And what's more, in my practical dataset, variables are named in alphabetic, i.e. A, B, C, D, E, ......, FK, FL, FM, FN, FO. So I can't label variables according to their name pattern, for example label variable mpg`n' "Mileage (mpg)" in a loop.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str14 make1 int price1 byte mpg1 float headroom1 str17 make2 int price2 byte mpg2 float headroom2 str17 make3 int price3 byte mpg3 float headroom3 str14 make4 int price4 byte mpg4 float headroom4 str14 make5 int price5 byte mpg5 float headroom5 "" . . . "" . . . "AMC Concord" 4099 22 2.5 "" . . . "" . . . "" . . . "" . . . "AMC Pacer" 4749 17 3 "" . . . "" . . . "" . . . "" . . . "" . . . "" . . . "" . . . "" . . . "" . . . "Buick Century" 4816 20 4.5 "" . . . "" . . . "" . . . "" . . . "" . . . "Buick Electra" 7827 15 4 "" . . . "" . . . "" . . . "Buick LeSabre" 5788 18 4 "" . . . "" . . . "" . . . "" . . . "" . . . "" . . . "" . . . "" . . . "" . . . "Buick Regal" 5189 20 2 "" . . . "" . . . "" . . . "" . . . "Buick Riviera" 10372 16 3.5 "" . . . "" . . . "" . . . "" . . . "Buick Skylark" 4082 19 3.5 "" . . . "" . . . end
Comment