Hello,
Is there a way to add a new variable on Stata that has different dimensions than the dataset that is in use, without first clearing the variable list?
For example,
Code:
use pharmacy_small
// calculate probability of each class on the test set
// '[:, 1]' at the end extracts the probability for each pharmacy to be under compliance
python: Y_mnb_score = mnb.fit(X_train, np.ravel(Y_train)).predict_proba(X_test)[:, 1]
// transfer the python variables Y_mnb_score as a Stata variable
python: Data.setObsTotal(len(Y_mnb_score))
python: Data.addVarFloat('mnbScore')
python: Data.store(var = 'mnbScore', obs = None, val = Y_mnb_score) // error: 'number of observations to set exceeds the limit of observations'
The error doesn't pop up when I first clear off the variables from the pharmacy_small data set and then execute the lines of python codes on Stata, but when I try to execute the python portion without first clearing out the dataset pharmacy_small, the error appears. I think the error pops up because the dimension of the variable 'mnbScore' that I am trying to add does not match with the dimension of the variables from the pharmacy_small dataset.
Is there a way to add a new variable on Stata that has different dimensions than the dataset that is in use, without first clearing the variable list?
Thank you,
Related Posts with Adding a new variable on Stata that has different dimensions than the variables from a dataset that is in use
Replacing values using a loopDear Stata users, I would like to execute the following command through a loop: replace q33_1=.a i…
generate a conditional variableguys, can you help me to generate a variable named "sandwich household'? sandwich household is a hou…
Replacing variables with loopsreplace c_q33_1=.a if c_q29_1 ==.a replace c_q33_2=.a if c_q29_2 ==.a replace c_q33_3=.a if c_q29_3 …
Allocation of 1 or 0 to a variable based on an odds ratio contained in another variable.I have a final dataset that contains the three variables shown in the table below. I need to assign …
loop questionHi all, I am new on Stata so my knowledge is limited. I have a variable that indicates whether the …
Subscribe to:
Post Comments (Atom)
0 Response to Adding a new variable on Stata that has different dimensions than the variables from a dataset that is in use
Post a Comment