Announcement

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

  • All variables are strings but I need it in numeric

    Dear all,

    I want to do a research on Swedish stocks. I have gathered a lot of data for this and now I am trying to work with it (do a time series analysis). But the problem is that all the data is still in string data. When I am trying to destring data and replace (destring variable_name, replace) It says: WC01001: contains nonnumeric characters; no replace. But there are no nonnumeric characters that I can see. I added in the Attachments a small part of my data because the whole file was too big to upload. I need to have all these variables in numerical variables so I can do regressions etc.
    Anyone know how to resolve this?

    Herman

    Attached Files

  • #2
    Please see FAQ Advice #12

    https://www.statalist.org/forums/help#stata

    on not posting spreadsheet attachments (please) and on using dataex (please).

    You were asked to read that before posting.

    Your problem is the spreadsheet-style header in observation 1 -- which contains many non-numeric characters. Stata doesn't want that stuff as data. It wants it as metadata. Here it seems that the headers would work fine as variable names in Stata.

    Code:
     
    orgno name year WC01001 WC01051 WC01151 WC01100 WC01101 WC01250 WC01253 WC01254 WC01266 WC18191 WC01251
    You can go back to import excel or import delimited and specify so that the first observation (row) becomes variable names. The dialog box versions

    Code:
    db import excel
    db import delimited
    make that easy.

    Or you can fix the problem by something like this.

    Code:
    foreach v of var * {
        local newname = `v'[1]
        capture rename `v' ``newname'
        label variable `v' "`newname'"
    }
    
    drop in 1
    and then try

    Code:
    destring, replace

    Comment

    Working...
    X