Announcement

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

  • Importing dataset from exel causing string variable and missing data

    Hi
    I have a large dataset in excel and when I am importing dataset into stata, most of the variables are becoming string variable. If I am using:
    destring, replace force

    all the string data is missing.
    However, I am using the below command and still the problem is not solved.

    help foreach
    ds, has(type string)

    foreach v in `r(varlist)' {
    di "`v'{col 33}" _n
    count if missing(real(`v')) & !missing(`v')
    }



    Could you guys please help how can I solve this problem?

  • #2
    The code you cite, which seems familiar somehow, is intended to show what the problem is, not to solve it.

    As is the rest of life force is the very last option you should use. It's not a good idea unless you are confident that it won't damage the content. An example could be that you know that a string variable is only string because there are a few instances of NA. The force option would just convert those to numeric missing . -- which is what you want. Otherwise force can be far too brutal.

    We need more details on what your data are to say more.
    Last edited by Nick Cox; 13 Nov 2023, 09:37.

    Comment

    Working...
    X