Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • cf export to excel

    Hi everybody,

    I compared two datsets with cf, which worked great. Now I was wondering if there is the possibility to export the variables and observations to an excel file. I did not find anything in the documentation about it. I use STATA 16.1

    Thanks!

  • #2
    Code:
    help export excel

    Comment


    • #3
      I'm reading between the lines and thinking that Marius Kaltenbach wants to export something "fancier" than the count of mismatches that -cf- offers. I would imagine, for example, that having a dataset with pairs of mismatched observations might be what's wanted. I show below one way to create a dataset like that.

      Code:
      sysuse auto, clear
      gen int id = _n  // We need an id variable, likely already available.
      order id  // I like
      tempfile file0
      save `file0'
      // Altered version for illustration
      set seed 9583
      foreach v of varlist make-foreign {
         quiet replace `v' = `v'[_n+1] if (_n > 1) & (runiform() > 0.95)
      }
      tempfile file1
      save `file1'
      clear
      // End of creating example data.
      //
      // Real work starts.
      use `file0'
      append using `file1', gen(fnum)
      // Create 0/1 indicators for any mismatches and count the "1" values.
      sort id fnum // ordered pairs
      foreach v of varlist make-foreign {
         by id: gen byte diff_`v' = (`v'[1] != `v'[2])
      }
      egen diffcount = rowtotal(diff*)
      label var diffcount "Number of mismatches"
      keep if diffcount > 0
      di _N/2 " observations with with at least one difference found."
      // Browse before exporting to Excel
      order id fnum diffcount
      browse
      export excel using "YourExcelFile", firstrow(variables)




      Comment

      Working...
      X