vars <- c("a", "b", "c", "x", "y", "z")
begin.var <- grep(pattern = "b", vars)
#The call grep(pattern, x) searches for a specified substring pattern in a vector x of strings
#and return its index positions.
end.var <- grep(pattern = "y", vars)
between.vars <- end.var - begin.var - 1
#Notice to use this method, make sure the names of vars are unique, otherwise it might be problematic.
Contains data from /Applications/Stata/ado/base/a/auto.dta
obs: 74 1978 Automobile Data
vars: 12 13 Apr 2011 17:45
size: 3,182 (_dta has notes)
--------------------------------------------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
--------------------------------------------------------------------------------------------------------------------------
make str18 %-18s Make and Model
price int %8.0gc Price
mpg int %8.0g Mileage (mpg)
rep78 int %8.0g Repair Record 1978
headroom float %6.1f Headroom (in.)
trunk int %8.0g Trunk space (cu. ft.)
weight int %8.0gc Weight (lbs.)
length int %8.0g Length (in.)
turn int %8.0g Turn Circle (ft.)
displacement int %8.0g Displacement (cu. in.)
gear_ratio float %6.2f Gear Ratio
foreign byte %8.0g origin Car type
--------------------------------------------------------------------------------------------------------------------------
Sorted by: foreign
. d price-foreign
storage display value
variable name type format label variable label
--------------------------------------------------------------------------------------------------------------------------
price int %8.0gc Price
mpg int %8.0g Mileage (mpg)
rep78 int %8.0g Repair Record 1978
headroom float %6.1f Headroom (in.)
trunk int %8.0g Trunk space (cu. ft.)
weight int %8.0gc Weight (lbs.)
length int %8.0g Length (in.)
turn int %8.0g Turn Circle (ft.)
displacement int %8.0g Displacement (cu. in.)
gear_ratio float %6.2f Gear Ratio
foreign byte %8.0g origin Car type
storage display value
variable name type format label variable label
--------------------------------------------------------------------------------------------------------------------------
price int %8.0gc Price
mpg int %8.0g Mileage (mpg)