Announcement

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

  • Internet download directly into STATA

    Dear all,

    I am looking to download the following data into STATA directly from the internet.
    https://info.finance.yahoo.co.jp/his...ed=25&tm=d&p=1

    i’d then like to add the following data to the same file.

    https://info.finance.yahoo.co.jp/history/?code=5408.T&sy=2012&sm=11&sd=25&ey=2017&em=12&ed= 25&tm=d&p=2


    Can anyone help me with this? Thanks in advance.

    Giles

  • #2
    Welcome to the Stata Forum/ Statalist,

    The site presents the information in a foreign language and I could not decipher its content.

    That being said, It seems there is a link to download a .csv file.

    You may download as .csv then - import delimited - to Stata and - save - as dta.

    To combine both datasets, already as .dta, you need to take a look at - merge - and - append - commands.

    To end, there is a Stata manual on data management. I know it can be challenging in the beginning, but coping with data management strategies is a crucial step.
    Best regards,

    Marcos

    Comment


    • #3
      Marcos

      Thanks for replying to me.

      The links above are from the Yahoo finance Japan website where to download the csv you need to live in Japan. I’m looking to download the links described straight into STATA straight from the internet. The data is all laid out if you scroll to the table which is the data I require which is time series data. I have already done this using VBA however i prefer manipulating data into STATA and this would save me a lot of time. Can you help please?

      i guess a command to link STATA to a url would be a good start.

      Giles

      Comment


      • #4
        Marcos wrote

        You may download as .csv then - import delimited - to Stata and - save - as dta.
        Expanding on that, it by reading help import and the clicking on the filename link, we see

        In most cases, where filename is a file that you are loading, filename may also be a URL.
        And indeed, we can demonstrate this with
        Code:
        import delimited http://www.stata.com/examples/auto.csv

        Comment


        • #5
          If you are interested in more data from yahoo I recommend instead using the mvport package (type: search mvport) and to look at this recent thread: https://www.statalist.org/forums/for...-data-download

          Comment


          • #6
            Dear All,

            For the regular yahoo finance the mvport package doesn't or even after doing the modification desired in the returnssyh.ado file.

            I have also tried the following code and I get the following error message. The url is taken from the source code on the yahoo website.

            Code:
            . import delimited https:​/​/​query1.finance.yahoo.com/​v7/​finance/​download/​BNO?​period1=1511646335&​period2=1514238335&​interval=1d&​events=history&​crumb=762h6if27xm.BNO.csv
            =exp not allowed
            r(101);
            Any ideas??

            Comment


            • #7
              Put quotation marks around your URL so Stata interprets it as a string - the equal sign is causing it to think you've got an expression in there somewhere.

              Comment


              • #8
                The following has downloaded 530 observations

                the problem is none of the observations are the table of date and share price which I need half way down the page. Could you please compare the webpage to the Stata ourput and advise how I get this table?

                Comment


                • #9
                  I know of no capability for Stata to read (as opposed to create) HTML files.

                  My comment at post #3 was the extent of my knowledge of using Stata to read directly from a file on the internet: it presupposes, as did the post from Marcos on which I was commenting, that the data are in a readily-interpretable format like CSV, not embedded within a page of HTML. And my comment at post #7 was very basic Stata, nothing particular to the import delimited command itself.

                  Comment


                  • #10
                    Dear All,

                    I have had another look this today. With the
                    Code:
                    import delimited
                    the data is actually coming into STATA as follows in one column: -

                    </tr><tr><td>2017年12月26日</td>
                    <td>736</td>
                    <td>738</td>
                    <td>721</td>
                    <td>722</td>
                    <td>85</td>
                    <td>722</td>

                    I can use the following to remove the "</td>" but this still appears in a single column.
                    Code:
                    import delimited "https://stocks.finance.yahoo.co.jp/stocks/history/?code=5408.T", delimiter("</td>")
                    This data should be in the following format as seven variables which I can then analyse.

                    Date Var1 Var2 Var3 Var4 Var5 Var6
                    2017年12月26日 736 738 721 722 85 722

                    How do I get the import delimited to bring this across into rows instead of columns.

                    Comment


                    • #11
                      Copying the table from the Web page and pasting it into a text editor (I use BBEdit for Mac) will produce a tab delimited file. I first translated the page into English with Google Translate.
                      Last edited by Steve Samuels; 26 Dec 2017, 14:08.
                      Steve Samuels
                      Statistical Consulting
                      [email protected]

                      Stata 14.2

                      Comment


                      • #12
                        The 'getsymbols' command will work for this:
                        https://youtu.be/Ro161kajKWc

                        Comment

                        Working...
                        X