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: generated file with append command has more than allowable number of variables


From   Tom Lutalo <tomlutalo@yahoo.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: generated file with append command has more than allowable number of variables
Date   Tue, 12 Mar 2013 08:17:43 -0700 (PDT)

Thanks Daniel,

this worked perfectly. I am in business


Tom



----- Original Message -----
From: daniel klein <klein.daniel.81@gmail.com>
To: statalist@hsphsun2.harvard.edu
Cc: 
Sent: Tuesday, March 12, 2013 2:05 PM
Subject: Re: st: generated file with append command has more than allowable number of variables

Something like this?

// start with master file
u <file_A>
unab varsa : *

// get variable names in dataset B
d using <file_B> ,varl
loc varsb `r(varlist)'

// get variables that appear in both datasets
loc allvars : list varsa & varsb

// add variables from using file
loc allvars `allvars' <vars_to_add>

// append
ap using <file_B> ,keep(`allvars')

Best
Daniel
-- 
Thanks Daniel,

The problem I have is that the variables I have in the master file are
not a subset of the variables in the using file.
Let me give an example;

file A has variables idno round sex1 sex2 sex3 sex4 violence1
violence2 health1 health2 health3 hiv1 hiv2
file B has variables idno round sex1 sex2 sex4 sex5 violence1
violence2 violence3 health1 health6 health7 hiv1 hiv2 hiv3 hiv4 hiv5

I would like to append using B and add to A only variables idno round
sex1 sex2 violence1 violence2 health1 hiv1 hiv2 (and also add hiv3
hiv4)

Is there any way of first comparing the two files and saving for use
only those variables found in the two files (to be used with the
option "keep")?

When I use the suggested I would receive a message "variable sex3 not
found in using file" as I would have stored it in the macro

Thank you again
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?searchhttp://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