Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[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 <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: generated file with append command has more than allowable number of variables
Date   Tue, 12 Mar 2013 01:56:38 -0700 (PDT)

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

Tom




----- Original Message -----
From: daniel klein <[email protected]>
To: [email protected]
Cc: 
Sent: Monday, March 11, 2013 6:56 PM
Subject: Re: st: generated file with append command has more than allowable number of variables

You do not need to type all the variable names by hand. Try something like this

u <shorter_file> ,clear
unab vars : *
loc vars `vars' <varnames_to_add>
ap using <longer_file> ,keep(`vars')

where, obviously, you do not type the < and >, and replace the content
inside with whatever filenames, and variable names you have.

Best
Daniel
-- 
Hi all,

I have two files, one (A) with 2045 variables while another (B) has
1055 variables. I wanted to append to A using B.
However since there are some variables in B which are not in A,  I end
up with more than the allowable 2048 variables for my version of STATA
(STATA 12)

I have to use the option "keep" and list what I want from B. This for
sure is too long a command.

I
only wanted to append to those variables already in A from B and maybe
add two new variables, thus remaining with either 2045 or with 2047 variables.

I am
using data from a cohort of individuals we have been following for over
10 years with many variables standing for questions asked at each
survey round (64 page
questionnaire).

Is there a command I can use to only append to
those variables that are already in my working file (A) and maybe also "keep"
only two more variables?

Thank you
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index