Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Keep data according to one data file's varlist


From   Zhangqunzi <zhangqunzi@googlemail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Keep data according to one data file's varlist
Date   Thu, 8 Nov 2012 11:09:35 +0100

Dear Sarah,

I tried your code
Use data2, clear
Ds
Use data1,
Keep 'r(varlist)'

I got the error message "no room to add more variables", do u have any suggestions about this?
Thanks

在 Nov 8, 2012,12:47 AM,"Sarah Edgington" <sedging@ucla.edu> 写道:

> I don't think I understand your question.
> This does not affect which observations are included in the data.  It only
> determines which variables are included.
> If this isn't clear to you, you might want to start with -help keep- to see
> how to keep/drop variables and how to keep/drop observations.
> 
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.
> harvard.edu] On Behalf Of Zhangqunzi
> Sent: Wednesday, November 07, 2012 3:02 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: Keep data according to one data file's varlist
> 
> Thanks a lot !
> 
> I will implement but will this approach gives me the new data set with the
> reduced varlist ?
> I mean I can also keep the observations according to the reduced varlist,
> right?
> 
> 
> 在 Nov 7, 2012,11:50 PM,"Sarah Edgington" <sedging@ucla.edu> 写道:
> 
>> See -help ds- for info on getting the list of the variables in your data.
>> 
>> Are there any variables in your second data file that do not exist in
>> the first?  If there aren't you could do something like:
>> 
>> use data2, clear
>> ds
>> use data1, clear
>> keep `r(varlist)'
>> 
>> If there are variables in data2 that don't exist in data1 this example
>> will produce errors, but if data2 is a strict subset of the variables
>> of the first file it should be fine.
>> 
>> -Sarah
>> 
>> -----Original Message-----
>> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.
>> harvard.edu] On Behalf Of Zhangqunzi
>> Sent: Wednesday, November 07, 2012 2:25 PM
>> To: statalist@hsphsun2.harvard.edu
>> Subject: Re: st: Keep data according to one data file's varlist
>> 
>> Actually, I want to make the two big data sets have the same variable
>> name list which is from the second file. Some variables in data file 1
>> need to be dropped.
>> 
>> I think I should creat a name list from data 2 then select the data
>> from data 1 according to this data 2 name list.
>> 
>> Can u tell me how to code in Stata?
>> Thanks
>> 
>> 在 Nov 7, 2012,7:46 PM,Nick Cox <njcoxstata@gmail.com> 写道:
>> 
>>> Sounds like
>>> 
>>> . drop var2 var4
>>> 
>>> Nick
>>> 
>>> On Wed, Nov 7, 2012 at 6:41 PM, Zhangqunzi
>>> <zhangqunzi@googlemail.com>
>> wrote:
>>> 
>>>> I have two dta files, first one with variables : var 1 2 3 4 5
>>>> Second one with
>>>> Variables: vart 1 3 5
>>>> 
>>>> As their names.
>>>> 
>>>> Now I would like to drop the extra variables in data file 1 which
>>>> are var
>> 2 4.
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>>> *   http://www.ats.ucla.edu/stat/stata/
>> 
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
>> 
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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