Con trăn ecotools

ecotools là gói Python chứa các hàm kinh tế lượng và các phím tắt thuận tiện để dữ liệu hoạt động với pandas và numpy. Tài liệu đầy đủ tại đây

Cài đặt

Bạn có thể cài đặt trực tiếp từ PYPI

$ pip install econtools

Hoặc bạn có thể sao chép từ Github và cài đặt trực tiếp

$ git clone http://github.com/dmsul/econtools
$ cd econtools
$ python setup.py install

kinh tế lượng

  • OLS, 2SLS, LIML
  • Tùy chọn để hấp thụ bất kỳ biến nào thông qua chuyển đổi bên trong (a la
    $ git clone http://github.com/dmsul/econtools
    $ cd econtools
    $ python setup.py install
    
    2 in Stata)
  • lỗi tiêu chuẩn mạnh mẽ
    • HAC (
      $ git clone http://github.com/dmsul/econtools
      $ cd econtools
      $ python setup.py install
      
      3/
      $ git clone http://github.com/dmsul/econtools
      $ cd econtools
      $ python setup.py install
      
      4,
      $ git clone http://github.com/dmsul/econtools
      $ cd econtools
      $ python setup.py install
      
      5,
      $ git clone http://github.com/dmsul/econtools
      $ cd econtools
      $ python setup.py install
      
      0)
    • Các lỗi tiêu chuẩn được nhóm lại
    • HAC không gian (SHAC, còn gọi là lỗi tiêu chuẩn Conley) với các hạt tam giác và đồng nhất
  • Kiểm tra F theo tên biến hoặc ma trận
    $ git clone http://github.com/dmsul/econtools
    $ cd econtools
    $ python setup.py install
    
    1
  • Hồi quy tuyến tính cục bộ
  • CẢNH BÁO [31 tháng 10 năm 2019]. Các giá trị dự đoán (yhat và phần dư) có thể không như mong đợi trong hồi quy đã chuyển đổi (khi sử dụng hiệu ứng cố định hoặc sử dụng trọng số). Đó là, hành vi hiện tại khác với Stata. Tôi đang xem xét vấn đề này và sẽ đăng bản sửa lỗi hoặc biện minh cho hành vi hiện tại trong tương lai gần
import econtools
import econtools.metrics as mt

# Read Stata DTA file
df = econtools.read('my_data.dta')

# Estimate OLS regression with fixed-effects and clustered s.e.'s
result = mt.reg(df,                     # DataFrame to use
                'y',                    # Outcome
                ['x1', 'x2'],           # Indep. Variables
                fe_name='person_id',    # Fixed-effects using variable 'person_id'
                cluster='state'         # Cluster by state
)

# Results
print(result.summary)                                # Print regression results
beta_x1 = result.beta['x1']                          # Get coefficient by variable name
r_squared = result.r2a                               # Get adjusted R-squared
joint_F = result.Ftest(['x1', 'x2'])                 # Test for joint significance
equality_F = result.Ftest(['x1', 'x2'], equal=True)  # Test for coeff. equality

Bảng thống kê hồi quy và tóm tắt

  • $ git clone http://github.com/dmsul/econtools
    $ cd econtools
    $ python setup.py install
    
    2 lấy kết quả hồi quy và tạo một đoạn bảng có định dạng LaTeX
  • $ git clone http://github.com/dmsul/econtools
    $ cd econtools
    $ python setup.py install
    
    3 có thể được sử dụng để thêm số liệu thống kê, ghi chú tùy ý, v.v. đến một cái bàn. Cũng có thể được sử dụng để tạo một bảng thống kê tổng hợp
  • $ git clone http://github.com/dmsul/econtools
    $ cd econtools
    $ python setup.py install
    
    4 giúp dễ dàng lưu ghi chú bảng phụ thuộc vào dữ liệu của bạn

linh tinh. Công cụ thao tác dữ liệu

  • $ git clone http://github.com/dmsul/econtools
    $ cd econtools
    $ python setup.py install
    
    5 bao bọc
    $ git clone http://github.com/dmsul/econtools
    $ cd econtools
    $ python setup.py install
    
    6 và bổ sung nhiều tính năng hợp nhất của Stata như cờ
    $ git clone http://github.com/dmsul/econtools
    $ cd econtools
    $ python setup.py install
    
    7 để hợp nhất thành công các quan sát
  • $ git clone http://github.com/dmsul/econtools
    $ cd econtools
    $ python setup.py install
    
    8 tạo ID dựa trên các biến trong quá khứ (so sánh
    $ git clone http://github.com/dmsul/econtools
    $ cd econtools
    $ python setup.py install
    
    9)
  • Lối băng qua đường chữ U thông dụng. S. nhãn nhà nước
    • Tiểu bang viết tắt thành tên tiểu bang (và ngược lại)
    • Bang chuyển sang tên bang (và đảo ngược)

Dữ liệu vào/ra

  • import econtools
    import econtools.metrics as mt
    
    # Read Stata DTA file
    df = econtools.read('my_data.dta')
    
    # Estimate OLS regression with fixed-effects and clustered s.e.'s
    result = mt.reg(df,                     # DataFrame to use
                    'y',                    # Outcome
                    ['x1', 'x2'],           # Indep. Variables
                    fe_name='person_id',    # Fixed-effects using variable 'person_id'
                    cluster='state'         # Cluster by state
    )
    
    # Results
    print(result.summary)                                # Print regression results
    beta_x1 = result.beta['x1']                          # Get coefficient by variable name
    r_squared = result.r2a                               # Get adjusted R-squared
    joint_F = result.Ftest(['x1', 'x2'])                 # Test for joint significance
    equality_F = result.Ftest(['x1', 'x2'], equal=True)  # Test for coeff. equality
    
    0 và
    import econtools
    import econtools.metrics as mt
    
    # Read Stata DTA file
    df = econtools.read('my_data.dta')
    
    # Estimate OLS regression with fixed-effects and clustered s.e.'s
    result = mt.reg(df,                     # DataFrame to use
                    'y',                    # Outcome
                    ['x1', 'x2'],           # Indep. Variables
                    fe_name='person_id',    # Fixed-effects using variable 'person_id'
                    cluster='state'         # Cluster by state
    )
    
    # Results
    print(result.summary)                                # Print regression results
    beta_x1 = result.beta['x1']                          # Get coefficient by variable name
    r_squared = result.r2a                               # Get adjusted R-squared
    joint_F = result.Ftest(['x1', 'x2'])                 # Test for joint significance
    equality_F = result.Ftest(['x1', 'x2'], equal=True)  # Test for coeff. equality
    
    1. Sử dụng phần mở rộng của đường dẫn tệp đã truyền để xác định phương pháp I/O
    import econtools
    import econtools.metrics as mt
    
    # Read Stata DTA file
    df = econtools.read('my_data.dta')
    
    # Estimate OLS regression with fixed-effects and clustered s.e.'s
    result = mt.reg(df,                     # DataFrame to use
                    'y',                    # Outcome
                    ['x1', 'x2'],           # Indep. Variables
                    fe_name='person_id',    # Fixed-effects using variable 'person_id'
                    cluster='state'         # Cluster by state
    )
    
    # Results
    print(result.summary)                                # Print regression results
    beta_x1 = result.beta['x1']                          # Get coefficient by variable name
    r_squared = result.r2a                               # Get adjusted R-squared
    joint_F = result.Ftest(['x1', 'x2'])                 # Test for joint significance
    equality_F = result.Ftest(['x1', 'x2'], equal=True)  # Test for coeff. equality
    
    2 nào sẽ sử dụng. Hữu ích cho việc viết các hàm đọc DataFrames theo chương trình từ đĩa được lưu ở các định dạng khác nhau. Xem ví dụ trên và dưới

  • import econtools
    import econtools.metrics as mt
    
    # Read Stata DTA file
    df = econtools.read('my_data.dta')
    
    # Estimate OLS regression with fixed-effects and clustered s.e.'s
    result = mt.reg(df,                     # DataFrame to use
                    'y',                    # Outcome
                    ['x1', 'x2'],           # Indep. Variables
                    fe_name='person_id',    # Fixed-effects using variable 'person_id'
                    cluster='state'         # Cluster by state
    )
    
    # Results
    print(result.summary)                                # Print regression results
    beta_x1 = result.beta['x1']                          # Get coefficient by variable name
    r_squared = result.r2a                               # Get adjusted R-squared
    joint_F = result.Ftest(['x1', 'x2'])                 # Test for joint significance
    equality_F = result.Ftest(['x1', 'x2'], equal=True)  # Test for coeff. equality
    
    3. Trình trang trí chức năng lưu bộ dữ liệu vào đĩa. Chức năng này xây dựng tập dữ liệu được yêu cầu và lưu nó vào đĩa nếu nó chưa tồn tại trên đĩa. Nếu tập dữ liệu đã được lưu, nó chỉ cần tải nó, tiết kiệm thời gian tính toán và cho phép sử dụng một chức năng duy nhất để tải và tạo dữ liệu

    $ git clone http://github.com/dmsul/econtools
    $ cd econtools
    $ python setup.py install
    
    7

    Loại tệp được tự động phát hiện từ tên tệp đã truyền. Trong trường hợp này, Stata DTA từ

    import econtools
    import econtools.metrics as mt
    
    # Read Stata DTA file
    df = econtools.read('my_data.dta')
    
    # Estimate OLS regression with fixed-effects and clustered s.e.'s
    result = mt.reg(df,                     # DataFrame to use
                    'y',                    # Outcome
                    ['x1', 'x2'],           # Indep. Variables
                    fe_name='person_id',    # Fixed-effects using variable 'person_id'
                    cluster='state'         # Cluster by state
    )
    
    # Results
    print(result.summary)                                # Print regression results
    beta_x1 = result.beta['x1']                          # Get coefficient by variable name
    r_squared = result.r2a                               # Get adjusted R-squared
    joint_F = result.Ftest(['x1', 'x2'])                 # Test for joint significance
    equality_F = result.Ftest(['x1', 'x2'], equal=True)  # Test for coeff. equality
    
    4

  • import econtools
    import econtools.metrics as mt
    
    # Read Stata DTA file
    df = econtools.read('my_data.dta')
    
    # Estimate OLS regression with fixed-effects and clustered s.e.'s
    result = mt.reg(df,                     # DataFrame to use
                    'y',                    # Outcome
                    ['x1', 'x2'],           # Indep. Variables
                    fe_name='person_id',    # Fixed-effects using variable 'person_id'
                    cluster='state'         # Cluster by state
    )
    
    # Results
    print(result.summary)                                # Print regression results
    beta_x1 = result.beta['x1']                          # Get coefficient by variable name
    r_squared = result.r2a                               # Get adjusted R-squared
    joint_F = result.Ftest(['x1', 'x2'])                 # Test for joint significance
    equality_F = result.Ftest(['x1', 'x2'], equal=True)  # Test for coeff. equality
    
    5. Trình bao bọc đơn giản cho
    import econtools
    import econtools.metrics as mt
    
    # Read Stata DTA file
    df = econtools.read('my_data.dta')
    
    # Estimate OLS regression with fixed-effects and clustered s.e.'s
    result = mt.reg(df,                     # DataFrame to use
                    'y',                    # Outcome
                    ['x1', 'x2'],           # Indep. Variables
                    fe_name='person_id',    # Fixed-effects using variable 'person_id'
                    cluster='state'         # Cluster by state
    )
    
    # Results
    print(result.summary)                                # Print regression results
    beta_x1 = result.beta['x1']                          # Get coefficient by variable name
    r_squared = result.r2a                               # Get adjusted R-squared
    joint_F = result.Ftest(['x1', 'x2'])                 # Test for joint significance
    equality_F = result.Ftest(['x1', 'x2'], equal=True)  # Test for coeff. equality
    
    6 cho phép bạn sử dụng cờ
    import econtools
    import econtools.metrics as mt
    
    # Read Stata DTA file
    df = econtools.read('my_data.dta')
    
    # Estimate OLS regression with fixed-effects and clustered s.e.'s
    result = mt.reg(df,                     # DataFrame to use
                    'y',                    # Outcome
                    ['x1', 'x2'],           # Indep. Variables
                    fe_name='person_id',    # Fixed-effects using variable 'person_id'
                    cluster='state'         # Cluster by state
    )
    
    # Results
    print(result.summary)                                # Print regression results
    beta_x1 = result.beta['x1']                          # Get coefficient by variable name
    r_squared = result.r2a                               # Get adjusted R-squared
    joint_F = result.Ftest(['x1', 'x2'])                 # Test for joint significance
    equality_F = result.Ftest(['x1', 'x2'], equal=True)  # Test for coeff. equality
    
    7 trên dòng lệnh. Điều này cho phép bạn chạy hồi quy mà không ghi đè lên các kết quả trước đó và không sửa đổi mã theo bất kỳ cách nào (i. e. , nhận xét các dòng "lưu")