Announcement

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

  • Import JSON file to STATA

    Hey!

    I've been trying to import a JSON file into Stata but just cannot figure out how to make it work.
    At the moment the file is fairly small and I could thus just export it to CSV and import it that way, it then looks the following way in Stata:

    Click image for larger version

Name:	Screen Shot 2018-07-17 at 16.36.31.png
Views:	1
Size:	77.7 KB
ID:	1453808



    However, in the future I will have to import JSON files. I tried both the jsonio package and insheetjson, but cannot make it work. I am also very new to Stata, that's probably because why.

    Any hints/ideas?

    Best wishes,
    Tom

  • #2
    Tom Menard

    I've run into this problem before. What I usually do is use Python/Pandas. That is, you can use Python to read in the JSON file, and then use the df.to_stata() method to make it into a Stata file. It's been awhile since I've done this, but there are some different ways to do this, apparently.

    Matthew J. Baker

    Comment


    • #3
      Tom, JSON stands for JavaScript Object Notation, which means that the JSON record is a representation of some object, not necessarily fitting nicely into the concept of a rectangular table with numeric or string cells (though in a particular case it can be).

      First inquire with the documentation for the system upstream to understand what possible records you can get. If you have simple objects a la person={name,age,sex,marstat} then it is usually no problem to map it to Stata dataset, but your example hints that you have a more complex nested object (financial year records for every enterprise). Those nested objects are best placed into additional files (enterprise records separately from year records) with a common ID for merging. What exactly to extract and where to place it depends on the answer to the first question and also on what do you want to do with it later.

      When you are ready, refer to http://www.oracle.com/technetwork/ar...n-1973242.html for JSON reading via Java.

      Best, Sergiy

      Comment


      • #4
        Matthew J. Baker Sergiy Radyakin

        Thanks to both of you for your great advice! I ended up using a combination of your suggestions, placing the nested objects in additional files and converting the JSON files via Python/Pandas into Stata files.

        Comment

        Working...
        X