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: FW: How to compare file structure difference before append


From   Rebecca Pope <rebecca.a.pope@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: FW: How to compare file structure difference before append
Date   Wed, 9 Jan 2013 09:11:12 -0600

I don't know of any way to do this with an existing command. But, you
could always do something like the following. This makes use of the
extended macro functions.

*** Begin example ***
   * Create slightly changed copy of auto.dta *
sysuse auto.dta, clear
tostring price, replace
save autodemocopy.dta, replace

sysuse auto.dta, clear
   * Get a list of all the variables in your data set *
unab varlist: _all
   * Determine the type of all the variables in your data set *
foreach var of local varlist {
    local `var'_typ: type `var'
}

   * Checking the data set you want to -append- *
use autodemocopy, clear
foreach var of local varlist {
   cap confirm ``var'_typ' variable `var'
      if _rc {
          local typ: type `var'
          di "`var' was ``var'_typ' in master data and `typ' in current data"
      }
}
*** end ***

The -capture- before -confirm- is key because otherwise the loop ends
at the first failure. This code presents a list of the differences.
You can then decide whether you need to change the format (as you
would here) before appending or whether the differences are benign,
like if you had str6 and str9.

Hope this helps,
Rebecca


On Wed, Jan 9, 2013 at 6:50 AM, rasool.bux <rasool.bux@aku.edu> wrote:
>
> I have seen user written program -cfvars- but it is just comparing variable names. Any suggestions.
> Regards
> Rasool Bux
>
> -----Original Message-----
> From: rasool.bux
> Sent: Friday, December 21, 2012 11:17 AM
> To: 'statalist@hsphsun2.harvard.edu'
> Subject: how to know the file structure difference before append
>
> Dear Statalist users,
>
> Is there any way to compare the dta file structure of two files to see the differences in varnames, types and formats?
>
> Then I want to use the append to combine the observations of both files.
>
> Thanks
> Rasool Bux
>
> ________________________________
>
> This e-mail may contain information that is privileged or confidential. If you are not the intended recipient, please delete the e-mail and any attachments and notify us immediately.
>
>
> *
> *   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index