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 on April 23, and its replacement, statalist.org is already up and running.


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

st: Σχετ: st: Common variables in different datasets


From   Nikolaos Kanellopoulos <nkkanel@yahoo.gr>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Σχετ: st: Common variables in different datasets
Date   Sun, 18 Sep 2011 18:06:05 +0100 (BST)

Maarten,

thanks. That produces exactly what I was looking for.
I wnt to thanks Partho for bringing to my attention lookfor and lookfor_all.
Αρχικό μήνυμα -----
Απο: Maarten Buis <maartenlbuis@gmail.com>
Προς: statalist@hsphsun2.harvard.edu
Κοιν.: 
Στάλθηκε: 6:30 μ.μ. Τρίτη, 13 Σεπτεμβρίου 2011
Θεμα: Re: st: Common variables in different datasets

2011/9/13 Nikolaos Kanellopoulos :
> I have a set of data files (file1.dta, file2.dta,...,file20.dta). There are some common variables which appear in all files and some which appear only in some. I want to create an output/table where the rows will be the variable names and the columns will be the file names and the cells will indicate whether the variable appears in each file.

*----------- begin example ----------
// create some example files
tempfile file1 file2 file3 res

sysuse auto, clear
drop mpg
save `file1'

sysuse auto, clear
drop foreign
save `file2'

sysuse auto, clear
drop mpg foreign
save `file3'

// start collecting the information
use `file1', clear
desc , replace
keep name
gen file1 = "X"
save `res'
    
forvalues i = 2/3 {
    use `file`i'', clear
    desc, replace
    keep name
    gen file`i' = "X"
    merge 1:1 name using `res'
    drop _merge
    save `res', replace
}

// display the results
use `res', clear
list
*------------ end example -----------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------

*
*   For searches and help try:
*  http://www.stata.com/help.cgi?searchhttp://www.stata.com/support/statalist/faqhttp://www.ats.ucla.edu/stat/stata/


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


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