Announcement

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

  • How can I change a string variable/numeric variable when merging different files?

    Hi guys,

    I'm pretty new to Stata and I'm trying to merge several different chunk files (.dta). When I tried to do it, the following error message popped up:

    variable CLOSDATE is str10 in master but int in using data
    You could specify append's force option to ignore this string/numeric mismatch. The using variable
    would then be treated as if it contained "".

    In my chunk files, CLOSDATE is written as DD/MM/YYYY, e.g. 31/12/2015.

    Does anyone of you know how I can change it in order to merge my chunk files?

    Thank you very much in advance for your help!

  • #2
    Welcome to the Stata Forum / Statalist.

    In order to merge, as Stata is telling you, you need to have both variables under the same form.

    This is the same with append.

    That said, there is a difference between append and merge.

    Please read the help file on the commands - append - and - merge - and see whether they are helpful to your case.

    If not, I kindly remind that the best way to get an insightful reply is sharing data (full, abridged, or a toy example) under CODE delimiters or by installing the SSC dataex, as recommended in the FAQ.
    Best regards,

    Marcos

    Comment


    • #3
      Hi Ferdi,

      To add to what Marcos has said: the issue is that your date variable CLOSDATE is sometimes numeric ("int" is a Stata numeric format) and sometimes string ("str10" is a Stata string format). You need CLOSDATE to be either string or numeric throughout. I would recommend using numeric, as there is less scope for variation (e.g. DD/MM/YYYY vs DD-MM-YYYY and so on). In order to convert a date from string to numeric, see help datetime_translation (in Stata 14 at least). Make sure you eyeball the original and converted dates such that you are happy the conversion is correct.

      Hope that helps,

      David.


      Comment


      • #4
        Thank you very much for your comments and help, it did work out!

        Comment


        • #5
          r

          Comment

          Working...
          X