Announcement

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

  • sfi module Data.store not working -- Please Help

    Hello,
    I am new to STATA and I am trying to export a Python variable to Stata.

    Below is my do-file:

    clear

    python:

    import sklearn.datasets as skdata
    import numpy as np
    from sfi import Data

    iris = skdata.load_iris()
    from sklearn.naive_bayes import GaussianNB

    GNB = GaussianNB()
    GNB_fit = GNB.fit(iris.data, iris.target).predict(iris.data)

    Data.addVarInt('GNB_fit')
    Data.store('GNB_fit', None, GNB_fit)

    end


    When I execute above commands, the new variable GNB_fit appears in the list on the top right hand corner of the STATA window, but the variable does not contain any data.
    How can I fix this issue?

    Thank you,

    Dominique

  • #2
    Dominique Bourget

    You need to call
    Code:
    setObsTotal()
    when starting with an empty dataset. In your case, adding one statement
    Code:
    Data.setObsTotal(len(GNB_fit))
    before
    Code:
    Data.addVarInt('GNB_fit')
    will fix the issue.

    Comment

    Working...
    X