Announcement

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

  • Importing SPSS data file into STATA by usespss command, but the date variable did not as expected.

    Dear statalists,

    I imported the SPSS data file into STATA by using "usespss" command.
    But the date variable did not as expected.

    For example,
    Date from SPSS Date from STATA
    14-Jun-2554 30662841600
    23-Jan-2557 30745267200
    19-Jun-2555 30694809600

    #1 question:
    Because of Buddhist Era (B.E.), How to change B.E. into A.D.?
    I try to subtract 543 years for correction in A.D., but it is not correct because the unit of date variable in STATA is not year.

    #2 question:
    If I changed BE into AD completely, How to change the format of date in STATA as same as SPSS.

    Thank you in advance.

    Best,
    Tanarat

  • #2
    Welcome to the Stata Forum/ Statalist.

    You need to take a look at datetime operations.

    If the variable was taken by Stata as a date, the starting point is January 1st, 1960.

    Once you transform the variable in years (you may divide by 365.25) you may further transform according to your needs.

    Please read the FAQ, particularly the topics about sharing data/outt/command.
    Best regards,

    Marcos

    Comment


    • #3
      Tanarat:
      as Marcos correctly pointed out, dealing with dates is a bit tricky and I do share his recommendation about getting yourself familiar with date related entries in Stata .pdf manual.
      That said, I do hope that what follows can do the trick:
      Code:
      . set obs 1
      
      . g date=30662841600
      
      . gen statadate = dofc(( date *1000) + tc(14oct1582 00:00))
      
      . format statadate %td
      
           +---------------------+
           |    date   statadate |
           |---------------------|
        1. | 3.1e+10   14jun2554 |
           +---------------------+
      
      . generate day = day( statadate )
      
      . generate month = month( statadate )
      
      . generate year = year( statadate )
      
      . replace year=year-554
      (1 real change made)
      
      . generate new_statadate = mdy( month , day, year )
      
      . format new_statadate %td
      
      . list
      
           +-------------------------------------------------------+
           |     date   statadate   day   month   year   new_sta~e |
           |-------------------------------------------------------|
        1. | 3.07e+10   14jun2554    14       6   2000   14jun2000 |
           +-------------------------------------------------------+
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Thank you very much for the useful guideline and the tricky. I will do my best.

        Comment


        • #5
          Tanarat Muangmool

          I am not sure how -usespss- is related. The dates are just numbers, and usespss transfers these numbers from one format to another. The interpretation of those numbers is key. Note that after conversion -usespss- will indicate if some variables were dates in the original SPSS system file, and offer you a possibility to convert them to proper Stata dates. See for example with your benchmark:

          Click image for larger version

Name:	usespss_dates.png
Views:	1
Size:	14.1 KB
ID:	1477791


          If you don't click the blue link the dates will remain as numbers (as the first list shows) and it is your responsibility to manage them. But if you click on the blue link, -usespss- will attempt to convert the original SPSS date/time variables to their respective matches in Stata (%tc formatted). The result is shown above after the second list statement. From that point on you can manipulate them using all Stata's toolbox of working with the dates.

          Calendar adjustments are beyond this feature. But if the calendar used for the dates is somehow marked in the SPSS system file, please provide an example.

          Best, Sergiy Radyakin

          Comment


          • #6
            Hello Sergiy Radyakin,

            I was trying to use 'USESPSS" since the files I was trying to convert in SPSS kept on giving error 6254
            Anyways, the file was converted and prompted me to use the date conversion, which I did.
            However, some of the dates were not converted. What to do about them now??

            FOllowing message appears

            Couldn't adjust date format of variable FC3_1.
            Kindly notify the author about this fact and provide the following information: f=1313280, t=20, and w=10.
            The values of this variable will not be modified and should not be used as dates without special care.


            Pease advice

            Comment


            • #7
              The message that Kamal Preet has encountered indicates that -usespss- has encountered a data file which exhibits either a very rare or new variable formatting settings, that the author of the program hasn't encountered and tested against. For safety the data left as a number, which may appear meaningless in Stata and look like some weird number.

              Originally posted by Kamal Preet View Post
              I was trying to use 'USESPSS" since the files I was trying to convert in SPSS kept on giving error 6254
              Kamal Preet ,
              1. what was the sequence of your actions that let to SPSS issuing you the error #6254? What is the description of this error in SPSS system?
              2. how was the data file created and is it behaving normally in SPSS in all other respects?
              3. can you share with me privately the whole data file or (if #2 is positive) just this single column FC3_1?
              4. can you share with me privately the full log of what -usespss- was telling from start of conversion untill you encountered the message?
              5. it would be helpful if you could investigate with other/alternative tools what is their behavior on encountering such data, and summarize the behavior in your message.
              For the moment, my H0 hypothesis is that the data file was produced by some alternative tool, which itself didn't conform to the SPSS requirements, causing the SPSS to fail saving as Stata data, and -usespss- failing to recognize the format for dates conversion (this is the last step of conversion).

              Best, Sergiy Radyakin

              Comment


              • #8
                Hello Sergiy Radyakin,

                I was trying to export data from SPSS to STATA using SPSS. I tried both syntax and drop down menu, same error 6254 which on little bit of search on the web indicates that data is not Unicode. However, on checking the data was very much in Unicode format. I also tried to change names for very long names. But same error.

                With USESPSS, I changed the date format to dd-mmm-yy format for all the variables and tried converting it. However, the same problem, some of the variables did not convert back to a meaningful time variable. This is an administrative data set from last 7 years and had 300,000 observations with over 2000 variables. However, I am trying to use convert a much smaller data set from 612 individuals, with only 4 repeated measures. which has about 2448 records.

                Unfortunately, I cannot share the file due to security reasons.

                Comment

                Working...
                X