本文整理汇总了Python中pandas.io.stata.StataReader.read方法的典型用法代码示例。如果您正苦于以下问题:Python StataReader.read方法的具体用法?Python StataReader.read怎么用?Python StataReader.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.io.stata.StataReader
的用法示例。
在下文中一共展示了StataReader.read方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read_dta1
# 需要导入模块: from pandas.io.stata import StataReader [as 别名]
# 或者: from pandas.io.stata.StataReader import read [as 别名]
def test_read_dta1(self):
reader_114 = StataReader(self.dta1_114)
parsed_114 = reader_114.read()
reader_117 = StataReader(self.dta1_117)
parsed_117 = reader_117.read()
# Pandas uses np.nan as missing value.
# Thus, all columns will be of type float, regardless of their name.
expected = DataFrame([(np.nan, np.nan, np.nan, np.nan, np.nan)],
columns=['float_miss', 'double_miss', 'byte_miss',
'int_miss', 'long_miss'])
# this is an oddity as really the nan should be float64, but
# the casting doesn't fail so need to match stata here
expected['float_miss'] = expected['float_miss'].astype(np.float32)
tm.assert_frame_equal(parsed_114, expected)
tm.assert_frame_equal(parsed_117, expected)
示例2: test_data_method
# 需要导入模块: from pandas.io.stata import StataReader [as 别名]
# 或者: from pandas.io.stata.StataReader import read [as 别名]
def test_data_method(self):
# Minimal testing of legacy data method
reader_114 = StataReader(self.dta1_114)
with warnings.catch_warnings(record=True) as w:
parsed_114_data = reader_114.data()
reader_114 = StataReader(self.dta1_114)
parsed_114_read = reader_114.read()
tm.assert_frame_equal(parsed_114_data, parsed_114_read)
示例3: StataReader
# 需要导入模块: from pandas.io.stata import StataReader [as 别名]
# 或者: from pandas.io.stata.StataReader import read [as 别名]
if not os.path.exists(paths.data):
os.mkdir(paths.data)
'''Load and Cache Datasets
-----------------------
Notes:
- Ensures no overlap in id
- Trims observations with any labor income over $300,000 (U.S., 2014)
'''
#--------------------------------------------------------------------
print "Loading PSID"
reader = StataReader(paths.psid)
psid = reader.read(convert_dates=False, convert_categoricals=False)
psid = psid.dropna(subset=['id']).set_index('id')
# Trimming
inc = psid.filter(regex='^inc_labor[0-9][0-9]')
psid = psid.loc[psid.male == 0]
psid = psid.loc[psid.black == 1]
psid = psid.loc[((inc < inc.quantile(0.90)) | (inc.isnull())).all(axis=1)]
# Interpolating
plong = pd.wide_to_long(psid[inc.columns].reset_index(),
['inc_labor'], i='id', j='age').sort_index()
plong = plong.interpolate(limit=5)
pwide = plong.unstack()
pwide.columns = pwide.columns.droplevel(0)
pwide.columns = ['{}{}'.format('inc_labor', a) for a in pwide.columns]
示例4: StataReader
# 需要导入模块: from pandas.io.stata import StataReader [as 别名]
# 或者: from pandas.io.stata.StataReader import read [as 别名]
Desc: This code selects the IPW variables for specific ABC outcomes.
We only do this for the pooled sample to increase power. We use
a linear probiaility model for this. We select the 3 variables
that minimize the BIC.
"""
import pandas as pd
from pandas.io.stata import StataReader
import numpy as np
import statsmodels.api as sm
from patsy import dmatrices
import itertools
from paths import paths
# import data
reader = StataReader(paths.abccare)
data = reader.read(convert_dates=False, convert_categoricals=False)
data = data.set_index('id')
data = data.sort_index()
data.drop(data.loc[(data.RV==1) & (data.R==0)].index, inplace=True)
# bring in outcomes files, and find the ABC-only/CARE-only ones
outcomes = pd.read_csv(paths.outcomes, index_col='variable')
only_abc = outcomes.loc[outcomes.only_abc == 1].index
only_care = outcomes.loc[outcomes.only_care == 1].index
bank = pd.read_csv(paths.controls)
ipwvars = np.unique(outcomes.loc[~outcomes.ipw_var.isnull(),'ipw_var'].get_values())
# generate the list of all possible models
models = itertools.chain.from_iterable([itertools.combinations(bank.loc[:, 'variable'], 3)])
models = list(models)