Announcement

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

  • A command to quickly browse another dataset on the disk (not currently in memory)

    One of my students asked me about writing a console program which could quickly browse the data from a dataset that was not in memory. It's fairly straightforward to -describe- the data on disk, and it was easy to write a program which can -list- part of the data by doing a quick preserve ---> use ---> list [in] ---> restore command. However, I wanted to see about writing a program to view the data in the browser (which a lot of people still like).

    The problem is that the open browser window doesn't pause the program and the -restore- will proceed immediately and you won't see the data on disk. The only way I found of halting the loop was to do this klugy -display- _request() line to ask for user input.

    Is there a better way to do this? Is there an existing program on SSC that browses non-memory data that I'm not aware of?

    Code:
    program brdisk
        syntax [namelist] [if] [in] using
        preserve
        qui use `using'
        br `namelist' `if' `in'
        di "Press Enter When Finished" _request(finish)
        restore
    end

  • #2
    You could open another Stata to look at the other dataset. I know that's probably not what you want, but I thought I would mention it.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      You could open another Stata to look at the other dataset. I know that's probably not what you want, but I thought I would mention it.
      I've done this in the past, but it seems a little overkill when all you really want to do is to look at the file's contents. As a more lightweight solution, I've used the data viewer in Stat/Transfer to browse the data (though the Mac version is so clunky, I sort of gave up on it.)

      Comment


      • #4
        1) What about double-clicking a file in Explorer (if you are using Windows)
        or an equivalent of same on other platforms?
        The extra benefit is nothing additional to install, and no need to type the file paths

        2) Nick also has given a very good suggestion. Starting Stata is often faster then preserving and restoring a dataset.

        Click image for larger version

Name:	browse.png
Views:	1
Size:	6.5 KB
ID:	1351887


        3) Your command template is rather optimistic. For the same reason you are [consciously or subconsciously] using namelist instead of varlist, you will have problems with if and in.

        Code:
        clear all
        
        program foo
           syntax [in]
           
           use auto `in'
        end
        
        foo in 1/10
        4) display is not too bad of a solution in this context. But if you prefer GUI, try:
        Code:
        clear
        sysuse auto
        browse
        window stopbox note "Click ok :)"
        clear

        Best, Sergiy Radyakin

        Comment


        • #5
          Thanks Sergiy
          1) I'm under a Mac. I can hack the behavior of Stata to open another instance in the way you suggest, but I messing with that behavior is not always a great idea under OSX.
          2) Your point about overhead is probably right. Frankly, part of the reason I did it this way was my personal preference to avoid leaving the current application window where possible. The moment you open up a simultaneous instance of Stata (which under OSX you already have to trick the system via command line), it starts to become difficult to track which instance you are in and the natural workflow you're used to starts to fall apart.
          3) I didn't think about the fact that [in] has to respect the current number of observations and [if] has to respect the variables in memory. I was very conciously using namelist for that reason. The command is already a kluge that's not meant for production and doesn't need a lot of error handling. I guess I could just replace the namelist and [if] [in] with arbitrary text based options
          4) Thanks for the tip on window. I wasn't aware that Stata provided facilities for dialog programming.

          As a side note, it would be nice if there was simply a lightweight viewer for stata .dta files packaged in with Stata. The existence of such a viewer would probably satisfy a lot of people's desires to "look" at multiple datasets simultaneously without interfering with the I/O framework of the core program.
          Last edited by Malcolm Wardlaw; 04 Aug 2016, 15:01.

          Comment


          • #6
            Fortunately, now we have -frame- in Stata 16 since 26 June 2019.
            Last edited by Chen Samulsion; 27 Oct 2021, 17:21.

            Comment

            Working...
            X