Announcement

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

  • Data Categorization txt file

    Dear All

    I have daily share price data in a txt file.

    The issue is to split the variables into different columns. Variables are Date Symbol High Low Close Open TradingVolume.

    Importing the txt file in stata provides all the information in one column.

    Please find below the data imported in Stata:

    Click image for larger version

Name:	Screenshot 2020-01-29 at 2.11.28 PM.png
Views:	1
Size:	80.7 KB
ID:	1534152


    Will appreciate if I can get help on splitting the information in different columns.

    Best regards

    Yahya Ghazali

  • #2
    see
    Code:
    help split
    especially the parse option

    also, please read the FAQ and follow it (e.g., here you should have used -dataex- and then someone might give you exact code that was tested)

    Comment


    • #3
      Given what you have, Rich's advice will give you what you want.

      But assuming you started by importing the text file, importing it again but this time setting the input delimiter to "|"
      Code:
      import delimited ... , delimiters("|")
      would avoid the problem in the first place, and would have separated your variable names as well.

      If you used Stata's menus to import the text file, choose the custom delimiter option to specify this option

      Comment


      • #4
        Originally posted by William Lisowski View Post
        ... would avoid the problem in the first place, and would have separated your variable names as well.
        I was also thinking about suggesting the use of import delimited, since Yahya Ghazali specifically mentioned that he starts with the text file, not data in memory, but I was stopped by noticing the single variable name is not something that Stata would have created if the names contained a pipe character as a delimiter (given the insheet command was used. import delimited would just detect the delimiter and import varnames correctly right away). So, probably the info_4....closin is exactly the value in the first row as the name of a single column in the data file --> that would have been more helpful in setting the problem, rather than distorted view after importing to Stata with an unknown command.



        EDIT: on a second thought, that varname could have been combined by Stata if the underscores were already there.
        Last edited by Sergiy Radyakin; 29 Jan 2020, 16:22.

        Comment

        Working...
        X