Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Dropping Subset of Variables

From   "Gauri Khanna" <>
Subject   Re: st: Dropping Subset of Variables
Date   Thu, 29 Mar 2007 12:06:25 +0000

Dear Neil,

I will try out your command that you sent.

As an explanation (and sorry for not being clear): I use the -describe- command below. As you see, I have a bunch of variables (I have copied a subset from my data set as an example ). I am interested in getting rid of variables with _02 to _46 in the first set with hv* characters (hence hvidx_02, h101_02 etc . uptil _46). I also have more variables (also shown below) that share the same suffix _01,_02 .... which I woud like to keep. Hence, my question is how can I get rid of the variabeles with hv*_02 to hv*_46.

hvidx_01 byte %8.0g line number
hv101_01 byte %8.0g hv101_01 relationship to head
hv102_01 byte %8.0g hv102_01 usual resident
hv103_01 byte %8.0g hv103_01 slept last night
hv104_01 byte %8.0g hv104_01 sex of household member
hv105_01 byte %8.0g hv105_01 age of household members
hv106_01 byte %8.0g hv106_01 highest educational level
hv107_01 byte %8.0g hv107_01 highest year of education
hv108_01 byte %8.0g hv108_01 education in single years
hv109_01 byte %8.0g hv109_01 educational attainment
hv110_01 byte %8.0g hv110_01 member still in school
hv115_01 byte %8.0g hv115_01 current marital status
hv116_01 byte %8.0g hv116_01 currently, formerly, never m.
hv117_01 byte %8.0g hv117_01 eligibility for female intview
hvidx_02 byte %8.0g line number
hv101_02 byte %8.0g hv101_02 relationship to head
hv102_02 byte %8.0g hv102_02 usual resident
hv103_02 byte %8.0g hv103_02 slept last night
hv104_02 byte %8.0g hv104_02 sex of household member
hv105_02 byte %8.0g hv105_02 age of household members
hv106_02 byte %8.0g hv106_02 highest educational level
hv107_02 byte %8.0g hv107_02 highest year of education
hv108_02 byte %8.0g hv108_02 education in single years
hv109_02 byte %8.0g hv109_02 educational attainment
hv110_02 byte %8.0g hv110_02 member still in school
hv115_02 byte %8.0g hv115_02 current marital status
hv116_02 byte %8.0g hv116_02 currently, formerly, never m.
hv117_02 byte %8.0g hv117_02 eligibility for female intview
hvidx_03 byte %8.0g line number
hv101_03 byte %8.0g hv101_03 relationship to head
hv102_03 byte %8.0g hv102_03 usual resident
hv103_03 byte %8.0g hv103_03 slept last night
hv104_03 byte %8.0g hv104_03 sex of household member
hv105_03 byte %8.0g hv105_03 age of household members
hv106_03 byte %8.0g hv106_03 highest educational level
hv107_03 byte %8.0g hv107_03 highest year of education
hv108_03 byte %8.0g hv108_03 education in single years
hv109_03 byte %8.0g hv109_03 educational attainment
hv110_03 byte %8.0g hv110_03 member still in school
hv115_03 byte %8.0g hv115_03 current marital status
hv116_03 byte %8.0g hv116_03 currently, formerly, never m.
idxh4_01 byte %8.0g index to household schedule
sh09_01 byte %8.0g sh09_01 marital status
sh11_01 byte %8.0g sh11_01 can read and write
sh12_01 byte %8.0g sh12_01 ever been to school
sh13_01 byte %8.0g sh13_01 main reason never went to school
sh14_01 byte %8.0g highest grade
sh16_01 byte %8.0g sh16_01 main reason not going to school
sh17_01 byte %8.0g sh17_01 occupation
sh18_01 byte %8.0g sh18_01 work for salary
sh24_01 byte %8.0g sh24_01 chew tobacco
sh25_01 byte %8.0g sh25_01 drink alcohol
sh26_01 byte %8.0g sh26_01 smoke
sh27_01 byte %8.0g sh27_01 smoked regularly
shed4_01 byte %8.0g shed4_01 education
shed6_01 byte %8.0g shed6_01 education
shage_01 byte %8.0g age of hh members or from
woman's questionnaire
idxh4_02 byte %8.0g index to household schedule
sh09_02 byte %8.0g sh09_02 marital status
sh11_02 byte %8.0g sh11_02 can read and write
sh12_02 byte %8.0g sh12_02 ever been to school
sh13_02 byte %8.0g sh13_02 main reason never went to school
sh14_02 byte %8.0g highest grade
sh16_02 byte %8.0g sh16_02 main reason not going to school
sh17_02 byte %8.0g sh17_02 occupation
sh18_02 byte %8.0g sh18_02 work for salary
sh24_02 byte %8.0g sh24_02 chew tobacco
sh25_02 byte %8.0g sh25_02 drink alcohol
sh26_02 byte %8.0g sh26_02 smoke
sh27_02 byte %8.0g sh27_02 smoked regularly



From: "Neil Shephard" <>
Subject: Re: st: Dropping Subset of Variables
Date: Thu, 29 Mar 2007 11:13:30 +0100

On 3/29/07, Gauri Khanna <> wrote:

Unfortunately, the wild card does not help because I have other variables in
my data set that have _02, _03 etc. attached and which I may want to keep.
I want to try and get rid of these listed variabls only with the _02 to _46
I don't see what your trying to do, to start with you are saying you
have other variables with _02..._46 that you want to keep, and then
you say you want to get rid of variables only with the _02..._46
suffix.  This seems contradictory to me.

You can use the wild-card * in the middle so if you have...
. des

and you wanted to get rid of the hvidx_02 to hvidx_06 but retain all
of the hv101* and hv102 variables then you could use something like..

forval x in 1/6{
 drop hvidx_0`x'

Could you provide a clearer example of what you want to achieve.

The output from -describe- which will list the variable names, and
then say which you want to remove from the dataset.

"Every great advance in natural knowledge has involved the absolute
rejection of authority."  - Thomas H. Huxley

Email - /
Website -
Photos -
*   For searches and help try:
Express yourself instantly with MSN Messenger! Download today it's FREE!

* For searches and help try:

© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index