{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d8355f24-ed72-4b06-9b3f-9fbf7968e600",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "zsh:1: command not found: pip3.9\n"
     ]
    }
   ],
   "source": [
    "#!pip3.10 install pyreadstat"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "251badeb",
   "metadata": {},
   "source": [
    "# Example of importing data statistics from Stata\n",
    "- Extract data dictionary and data from Stata file\n",
    "- Apply weights to one or more variables\n",
    "- Set user defined missings\n",
    "- Export selective or all variables to NADA/MetadataEditor compatible format\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e5681242",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyreadstat\n",
    "import time\n",
    "import re\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os\n",
    "from src.FileInfo import FileInfo\n",
    "from src.VarInfo import VarInfo\n",
    "from src.DictParams import DictParams\n",
    "from src.DataUtils import DataUtils\n",
    "from src.DataDictionary import DataDictionary\n",
    "from statsmodels.stats.weightstats import DescrStatsW\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a078fb4d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# file is available at https://github.com/thousandoaks/Wooldridge/blob/master/lawsch85.dta\n",
    "filepath=\"/Volumes/webdev/editor/datafiles/editor/0c74b7f78409a4022a2c4c5a5ca3ee19/data/LAWSCH85.DTA\"\n",
    "\n",
    "# output CSV file path\n",
    "csvfile=\"/users/m2/Downloads/sample_data.csv\"\n",
    "\n",
    "datadict=DataDictionary()\n",
    "fileinfo= FileInfo(file_path=filepath)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "222bcda0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# get metadata for variables witout summary statistics\n",
    "metadata=datadict.get_metadata(fileinfo)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "17f2b59b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'rows': 156,\n",
       " 'columns': 21,\n",
       " 'variables': [{'name': 'rank',\n",
       "   'labl': 'law school ranking',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'salary',\n",
       "   'labl': 'median starting salary',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'cost',\n",
       "   'labl': 'law school cost',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'LSAT',\n",
       "   'labl': 'median LSAT score',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'GPA',\n",
       "   'labl': 'median college GPA',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'libvol',\n",
       "   'labl': 'no. volumes in lib., 1000s',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'faculty',\n",
       "   'labl': 'no. of faculty',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'age',\n",
       "   'labl': 'age of law sch., years',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'clsize',\n",
       "   'labl': 'size of entering class',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'north',\n",
       "   'labl': '=1 if law sch in north',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'south',\n",
       "   'labl': '=1 if law sch in south',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'east',\n",
       "   'labl': '=1 if law sch in east',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'west',\n",
       "   'labl': '=1 if law sch in west',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'lsalary',\n",
       "   'labl': 'log(salary)',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'studfac',\n",
       "   'labl': 'student-faculty ratio',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'top10',\n",
       "   'labl': '=1 if ranked in top 10',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'r11_25',\n",
       "   'labl': '=1 if ranked 11-25',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'r26_40',\n",
       "   'labl': '=1 if ranked 26-40',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'r41_60',\n",
       "   'labl': '=1 if ranked 41-60',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'llibvol',\n",
       "   'labl': 'log(libvol)',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []},\n",
       "  {'name': 'lcost',\n",
       "   'labl': 'log(cost)',\n",
       "   'var_intrvl': 'contin',\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'},\n",
       "   'var_catgry_labels': []}]}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "metadata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "691b734a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# get data dictionary with all summary statistics\n",
    "variable_dict=datadict.get_data_dictionary(fileinfo)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a2ccfa7f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'rows': 156,\n",
       " 'columns': 21,\n",
       " 'variables': [{'name': 'rank',\n",
       "   'labl': 'law school ranking',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '1.0',\n",
       "     'max': '175.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '1.0'},\n",
       "    {'type': 'max', 'value': '175.0'},\n",
       "    {'type': 'mean', 'value': '83.75'},\n",
       "    {'type': 'stdev', 'value': '50.064168501453565'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'salary',\n",
       "   'labl': 'median starting salary',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 148,\n",
       "     'min': '24900.0',\n",
       "     'max': '78325.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '148'},\n",
       "    {'type': 'invd', 'value': '8'},\n",
       "    {'type': 'min', 'value': '24900.0'},\n",
       "    {'type': 'max', 'value': '78325.0'},\n",
       "    {'type': 'mean', 'value': '38946.71621621621'},\n",
       "    {'type': 'stdev', 'value': '12188.840435292199'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'cost',\n",
       "   'labl': 'law school cost',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 150,\n",
       "     'min': '2623.0',\n",
       "     'max': '20518.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '150'},\n",
       "    {'type': 'invd', 'value': '6'},\n",
       "    {'type': 'min', 'value': '2623.0'},\n",
       "    {'type': 'max', 'value': '20518.0'},\n",
       "    {'type': 'mean', 'value': '12736.24'},\n",
       "    {'type': 'stdev', 'value': '4012.667528426854'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'LSAT',\n",
       "   'labl': 'median LSAT score',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 150,\n",
       "     'min': '140.0',\n",
       "     'max': '171.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '150'},\n",
       "    {'type': 'invd', 'value': '6'},\n",
       "    {'type': 'min', 'value': '140.0'},\n",
       "    {'type': 'max', 'value': '171.0'},\n",
       "    {'type': 'mean', 'value': '158.29333333333332'},\n",
       "    {'type': 'stdev', 'value': '4.701201712238041'}],\n",
       "   'var_catgry': [{'value': '140', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '145', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '146', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '149', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '151', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '152', 'stats': [{'type': 'freq', 'value': '7'}]},\n",
       "    {'value': '153', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '154', 'stats': [{'type': 'freq', 'value': '11'}]},\n",
       "    {'value': '155', 'stats': [{'type': 'freq', 'value': '16'}]},\n",
       "    {'value': '156', 'stats': [{'type': 'freq', 'value': '10'}]},\n",
       "    {'value': '157', 'stats': [{'type': 'freq', 'value': '15'}]},\n",
       "    {'value': '158', 'stats': [{'type': 'freq', 'value': '11'}]},\n",
       "    {'value': '159', 'stats': [{'type': 'freq', 'value': '12'}]},\n",
       "    {'value': '160', 'stats': [{'type': 'freq', 'value': '14'}]},\n",
       "    {'value': '161', 'stats': [{'type': 'freq', 'value': '10'}]},\n",
       "    {'value': '162', 'stats': [{'type': 'freq', 'value': '7'}]},\n",
       "    {'value': '163', 'stats': [{'type': 'freq', 'value': '11'}]},\n",
       "    {'value': '164', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '165', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '166', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '167', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '168', 'stats': [{'type': 'freq', 'value': '4'}]},\n",
       "    {'value': '169', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '171', 'stats': [{'type': 'freq', 'value': '1'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'GPA',\n",
       "   'labl': 'median college GPA',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 149,\n",
       "     'min': '2.7300000190734863',\n",
       "     'max': '3.819999933242798'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '149'},\n",
       "    {'type': 'invd', 'value': '7'},\n",
       "    {'type': 'min', 'value': '2.7300000190734863'},\n",
       "    {'type': 'max', 'value': '3.819999933242798'},\n",
       "    {'type': 'mean', 'value': '3.302751677148294'},\n",
       "    {'type': 'stdev', 'value': '0.19977642750979446'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'libvol',\n",
       "   'labl': 'no. volumes in lib., 1000s',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 155,\n",
       "     'min': '124.0',\n",
       "     'max': '1745.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '155'},\n",
       "    {'type': 'invd', 'value': '1'},\n",
       "    {'type': 'min', 'value': '124.0'},\n",
       "    {'type': 'max', 'value': '1745.0'},\n",
       "    {'type': 'mean', 'value': '347.0709677419355'},\n",
       "    {'type': 'stdev', 'value': '188.24221443266106'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'faculty',\n",
       "   'labl': 'no. of faculty',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 152,\n",
       "     'min': '17.0',\n",
       "     'max': '245.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '152'},\n",
       "    {'type': 'invd', 'value': '4'},\n",
       "    {'type': 'min', 'value': '17.0'},\n",
       "    {'type': 'max', 'value': '245.0'},\n",
       "    {'type': 'mean', 'value': '70.73026315789474'},\n",
       "    {'type': 'stdev', 'value': '39.2603755881298'}],\n",
       "   'var_catgry': [{'value': '17', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '18', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '22', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '23', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '27', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '28', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '31', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '32', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '33', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '35', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '36', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '37', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '38', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '39', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '40', 'stats': [{'type': 'freq', 'value': '6'}]},\n",
       "    {'value': '41', 'stats': [{'type': 'freq', 'value': '4'}]},\n",
       "    {'value': '42', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '43', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '44', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '45', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '47', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '48', 'stats': [{'type': 'freq', 'value': '6'}]},\n",
       "    {'value': '49', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '50', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '51', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '52', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '53', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '54', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '55', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '56', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '57', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '58', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '59', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '60', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '61', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '62', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '63', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '65', 'stats': [{'type': 'freq', 'value': '4'}]},\n",
       "    {'value': '66', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '67', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '68', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '69', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '72', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '74', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '75', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '78', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '80', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '82', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '83', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '86', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '87', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '88', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '89', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '91', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '93', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '95', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '96', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '97', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '100', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '101', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '103', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '105', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '107', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '109', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '111', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '113', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '114', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '128', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '130', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '136', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '138', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '148', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '150', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '154', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '187', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '188', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '190', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '196', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '206', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '245', 'stats': [{'type': 'freq', 'value': '1'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'age',\n",
       "   'labl': 'age of law sch., years',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 111,\n",
       "     'min': '3.0',\n",
       "     'max': '206.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '111'},\n",
       "    {'type': 'invd', 'value': '45'},\n",
       "    {'type': 'min', 'value': '3.0'},\n",
       "    {'type': 'max', 'value': '206.0'},\n",
       "    {'type': 'mean', 'value': '85.81981981981981'},\n",
       "    {'type': 'stdev', 'value': '40.89169691185334'}],\n",
       "   'var_catgry': [{'value': '3', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '6', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '9', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '10', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '12', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '13', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '20', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '23', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '24', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '26', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '29', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '31', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '32', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '34', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '38', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '56', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '58', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '59', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '60', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '61', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '62', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '65', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '70', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '71', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '72', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '73', 'stats': [{'type': 'freq', 'value': '4'}]},\n",
       "    {'value': '74', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '76', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '77', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '78', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '79', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '82', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '84', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '85', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '86', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '89', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '90', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '91', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '92', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '93', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '94', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '95', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '97', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '100', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '101', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '102', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '107', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '112', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '113', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '115', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '116', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '118', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '120', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '126', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '128', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '131', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '133', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '134', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '136', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '139', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '140', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '144', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '149', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '150', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '151', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '152', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '160', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '173', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '196', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '206', 'stats': [{'type': 'freq', 'value': '1'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'clsize',\n",
       "   'labl': 'size of entering class',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 153,\n",
       "     'min': '70.0',\n",
       "     'max': '679.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '153'},\n",
       "    {'type': 'invd', 'value': '3'},\n",
       "    {'type': 'min', 'value': '70.0'},\n",
       "    {'type': 'max', 'value': '679.0'},\n",
       "    {'type': 'mean', 'value': '241.83006535947712'},\n",
       "    {'type': 'stdev', 'value': '113.07227490983443'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'north',\n",
       "   'labl': '=1 if law sch in north',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.20512820512820512'},\n",
       "    {'type': 'stdev', 'value': '0.40509574683346666'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '124'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '32'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'south',\n",
       "   'labl': '=1 if law sch in south',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.24358974358974358'},\n",
       "    {'type': 'stdev', 'value': '0.43063036873259714'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '118'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '38'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'east',\n",
       "   'labl': '=1 if law sch in east',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.3076923076923077'},\n",
       "    {'type': 'stdev', 'value': '0.4630249016557855'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '108'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '48'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'west',\n",
       "   'labl': '=1 if law sch in west',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.24358974358974358'},\n",
       "    {'type': 'stdev', 'value': '0.4306303687325971'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '118'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '38'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'lsalary',\n",
       "   'labl': 'log(salary)',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 148,\n",
       "     'min': '10.122623443603516',\n",
       "     'max': '11.268622398376465'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '148'},\n",
       "    {'type': 'invd', 'value': '8'},\n",
       "    {'type': 'min', 'value': '10.122623443603516'},\n",
       "    {'type': 'max', 'value': '11.268622398376465'},\n",
       "    {'type': 'mean', 'value': '10.52877589174219'},\n",
       "    {'type': 'stdev', 'value': '0.27672044568411663'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'studfac',\n",
       "   'labl': 'student-faculty ratio',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 150,\n",
       "     'min': '1.0099999904632568',\n",
       "     'max': '9.342857360839844'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '150'},\n",
       "    {'type': 'invd', 'value': '6'},\n",
       "    {'type': 'min', 'value': '1.0099999904632568'},\n",
       "    {'type': 'max', 'value': '9.342857360839844'},\n",
       "    {'type': 'mean', 'value': '3.7066598542531333'},\n",
       "    {'type': 'stdev', 'value': '1.3118621080628194'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'top10',\n",
       "   'labl': '=1 if ranked in top 10',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.0641025641025641'},\n",
       "    {'type': 'stdev', 'value': '0.24572439792441947'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '146'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '10'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'r11_25',\n",
       "   'labl': '=1 if ranked 11-25',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.10256410256410256'},\n",
       "    {'type': 'stdev', 'value': '0.30436580663972007'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '140'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '16'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'r26_40',\n",
       "   'labl': '=1 if ranked 26-40',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.08333333333333333'},\n",
       "    {'type': 'stdev', 'value': '0.2772755316109005'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '143'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '13'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'r41_60',\n",
       "   'labl': '=1 if ranked 41-60',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.11538461538461539'},\n",
       "    {'type': 'stdev', 'value': '0.3205144747682703'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '138'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '18'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'llibvol',\n",
       "   'labl': 'log(libvol)',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 155,\n",
       "     'min': '4.820281505584717',\n",
       "     'max': '7.464509963989258'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '155'},\n",
       "    {'type': 'invd', 'value': '1'},\n",
       "    {'type': 'min', 'value': '4.820281505584717'},\n",
       "    {'type': 'max', 'value': '7.464509963989258'},\n",
       "    {'type': 'mean', 'value': '5.751980999977358'},\n",
       "    {'type': 'stdev', 'value': '0.4165479987301825'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'lcost',\n",
       "   'labl': 'log(cost)',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 150,\n",
       "     'min': '7.872074127197266',\n",
       "     'max': '9.929058074951172'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '150'},\n",
       "    {'type': 'invd', 'value': '6'},\n",
       "    {'type': 'min', 'value': '7.872074127197266'},\n",
       "    {'type': 'max', 'value': '9.929058074951172'},\n",
       "    {'type': 'mean', 'value': '9.39243366241455'},\n",
       "    {'type': 'stdev', 'value': '0.3689148449463717'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}}]}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "variable_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3b1c0e6e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weights:  {'top10': {'wgt_freq': {0: 826, 1: 64}, 'wgt_mean': 0.0724168303083735, 'wgt_stdev': 0.25932231036778775}}\n",
      "field= top10 value= 0\n",
      "freq_values {0: 826, 1: 64}\n",
      "field= top10 value= 1\n",
      "freq_values {0: 826, 1: 64}\n"
     ]
    }
   ],
   "source": [
    "params=DictParams(\n",
    "    file_path=filepath,\n",
    "    weights=[\n",
    "            {\n",
    "                \"field\": \"top10\",\n",
    "                \"weight_field\": \"llibvol\"\n",
    "            }\n",
    "        ]    \n",
    ")\n",
    "\n",
    "dict2=datadict.get_data_dictionary_variable(params)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f0cfda1b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'rows': 156,\n",
       " 'columns': 21,\n",
       " 'variables': [{'name': 'rank',\n",
       "   'labl': 'law school ranking',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '1.0',\n",
       "     'max': '175.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '1.0'},\n",
       "    {'type': 'max', 'value': '175.0'},\n",
       "    {'type': 'mean', 'value': '83.75'},\n",
       "    {'type': 'stdev', 'value': '50.064168501453565'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'salary',\n",
       "   'labl': 'median starting salary',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 148,\n",
       "     'min': '24900.0',\n",
       "     'max': '78325.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '148'},\n",
       "    {'type': 'invd', 'value': '8'},\n",
       "    {'type': 'min', 'value': '24900.0'},\n",
       "    {'type': 'max', 'value': '78325.0'},\n",
       "    {'type': 'mean', 'value': '38946.71621621621'},\n",
       "    {'type': 'stdev', 'value': '12188.840435292199'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'cost',\n",
       "   'labl': 'law school cost',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 150,\n",
       "     'min': '2623.0',\n",
       "     'max': '20518.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '150'},\n",
       "    {'type': 'invd', 'value': '6'},\n",
       "    {'type': 'min', 'value': '2623.0'},\n",
       "    {'type': 'max', 'value': '20518.0'},\n",
       "    {'type': 'mean', 'value': '12736.24'},\n",
       "    {'type': 'stdev', 'value': '4012.667528426854'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'LSAT',\n",
       "   'labl': 'median LSAT score',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 150,\n",
       "     'min': '140.0',\n",
       "     'max': '171.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '150'},\n",
       "    {'type': 'invd', 'value': '6'},\n",
       "    {'type': 'min', 'value': '140.0'},\n",
       "    {'type': 'max', 'value': '171.0'},\n",
       "    {'type': 'mean', 'value': '158.29333333333332'},\n",
       "    {'type': 'stdev', 'value': '4.701201712238041'}],\n",
       "   'var_catgry': [{'value': '140', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '145', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '146', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '149', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '151', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '152', 'stats': [{'type': 'freq', 'value': '7'}]},\n",
       "    {'value': '153', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '154', 'stats': [{'type': 'freq', 'value': '11'}]},\n",
       "    {'value': '155', 'stats': [{'type': 'freq', 'value': '16'}]},\n",
       "    {'value': '156', 'stats': [{'type': 'freq', 'value': '10'}]},\n",
       "    {'value': '157', 'stats': [{'type': 'freq', 'value': '15'}]},\n",
       "    {'value': '158', 'stats': [{'type': 'freq', 'value': '11'}]},\n",
       "    {'value': '159', 'stats': [{'type': 'freq', 'value': '12'}]},\n",
       "    {'value': '160', 'stats': [{'type': 'freq', 'value': '14'}]},\n",
       "    {'value': '161', 'stats': [{'type': 'freq', 'value': '10'}]},\n",
       "    {'value': '162', 'stats': [{'type': 'freq', 'value': '7'}]},\n",
       "    {'value': '163', 'stats': [{'type': 'freq', 'value': '11'}]},\n",
       "    {'value': '164', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '165', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '166', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '167', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '168', 'stats': [{'type': 'freq', 'value': '4'}]},\n",
       "    {'value': '169', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '171', 'stats': [{'type': 'freq', 'value': '1'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'GPA',\n",
       "   'labl': 'median college GPA',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 149,\n",
       "     'min': '2.7300000190734863',\n",
       "     'max': '3.819999933242798'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '149'},\n",
       "    {'type': 'invd', 'value': '7'},\n",
       "    {'type': 'min', 'value': '2.7300000190734863'},\n",
       "    {'type': 'max', 'value': '3.819999933242798'},\n",
       "    {'type': 'mean', 'value': '3.302751677148294'},\n",
       "    {'type': 'stdev', 'value': '0.19977642750979446'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'libvol',\n",
       "   'labl': 'no. volumes in lib., 1000s',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 155,\n",
       "     'min': '124.0',\n",
       "     'max': '1745.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '155'},\n",
       "    {'type': 'invd', 'value': '1'},\n",
       "    {'type': 'min', 'value': '124.0'},\n",
       "    {'type': 'max', 'value': '1745.0'},\n",
       "    {'type': 'mean', 'value': '347.0709677419355'},\n",
       "    {'type': 'stdev', 'value': '188.24221443266106'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'faculty',\n",
       "   'labl': 'no. of faculty',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 152,\n",
       "     'min': '17.0',\n",
       "     'max': '245.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '152'},\n",
       "    {'type': 'invd', 'value': '4'},\n",
       "    {'type': 'min', 'value': '17.0'},\n",
       "    {'type': 'max', 'value': '245.0'},\n",
       "    {'type': 'mean', 'value': '70.73026315789474'},\n",
       "    {'type': 'stdev', 'value': '39.2603755881298'}],\n",
       "   'var_catgry': [{'value': '17', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '18', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '22', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '23', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '27', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '28', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '31', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '32', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '33', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '35', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '36', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '37', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '38', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '39', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '40', 'stats': [{'type': 'freq', 'value': '6'}]},\n",
       "    {'value': '41', 'stats': [{'type': 'freq', 'value': '4'}]},\n",
       "    {'value': '42', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '43', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '44', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '45', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '47', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '48', 'stats': [{'type': 'freq', 'value': '6'}]},\n",
       "    {'value': '49', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '50', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '51', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '52', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '53', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '54', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '55', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '56', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '57', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '58', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '59', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '60', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '61', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '62', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '63', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '65', 'stats': [{'type': 'freq', 'value': '4'}]},\n",
       "    {'value': '66', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '67', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '68', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '69', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '72', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '74', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '75', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '78', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '80', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '82', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '83', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '86', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '87', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '88', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '89', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '91', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '93', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '95', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '96', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '97', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '100', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '101', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '103', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '105', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '107', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '109', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '111', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '113', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '114', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '128', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '130', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '136', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '138', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '148', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '150', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '154', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '187', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '188', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '190', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '196', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '206', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '245', 'stats': [{'type': 'freq', 'value': '1'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'age',\n",
       "   'labl': 'age of law sch., years',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 111,\n",
       "     'min': '3.0',\n",
       "     'max': '206.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '111'},\n",
       "    {'type': 'invd', 'value': '45'},\n",
       "    {'type': 'min', 'value': '3.0'},\n",
       "    {'type': 'max', 'value': '206.0'},\n",
       "    {'type': 'mean', 'value': '85.81981981981981'},\n",
       "    {'type': 'stdev', 'value': '40.89169691185334'}],\n",
       "   'var_catgry': [{'value': '3', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '6', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '9', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '10', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '12', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '13', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '20', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '23', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '24', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '26', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '29', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '31', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '32', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '34', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '38', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '56', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '58', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '59', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '60', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '61', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '62', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '65', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '70', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '71', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '72', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '73', 'stats': [{'type': 'freq', 'value': '4'}]},\n",
       "    {'value': '74', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '76', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '77', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '78', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '79', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '82', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '84', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '85', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '86', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '89', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '90', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '91', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '92', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '93', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '94', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '95', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '97', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '100', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '101', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '102', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '107', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '112', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '113', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '115', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '116', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '118', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '120', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '126', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '128', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '131', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '133', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '134', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '136', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '139', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '140', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '144', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '149', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '150', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '151', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '152', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '160', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '173', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '196', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '206', 'stats': [{'type': 'freq', 'value': '1'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'clsize',\n",
       "   'labl': 'size of entering class',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 153,\n",
       "     'min': '70.0',\n",
       "     'max': '679.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '153'},\n",
       "    {'type': 'invd', 'value': '3'},\n",
       "    {'type': 'min', 'value': '70.0'},\n",
       "    {'type': 'max', 'value': '679.0'},\n",
       "    {'type': 'mean', 'value': '241.83006535947712'},\n",
       "    {'type': 'stdev', 'value': '113.07227490983443'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'north',\n",
       "   'labl': '=1 if law sch in north',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.20512820512820512'},\n",
       "    {'type': 'stdev', 'value': '0.40509574683346666'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '124'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '32'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'south',\n",
       "   'labl': '=1 if law sch in south',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.24358974358974358'},\n",
       "    {'type': 'stdev', 'value': '0.43063036873259714'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '118'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '38'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'east',\n",
       "   'labl': '=1 if law sch in east',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.3076923076923077'},\n",
       "    {'type': 'stdev', 'value': '0.4630249016557855'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '108'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '48'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'west',\n",
       "   'labl': '=1 if law sch in west',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.24358974358974358'},\n",
       "    {'type': 'stdev', 'value': '0.4306303687325971'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '118'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '38'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'lsalary',\n",
       "   'labl': 'log(salary)',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 148,\n",
       "     'min': '10.122623443603516',\n",
       "     'max': '11.268622398376465'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '148'},\n",
       "    {'type': 'invd', 'value': '8'},\n",
       "    {'type': 'min', 'value': '10.122623443603516'},\n",
       "    {'type': 'max', 'value': '11.268622398376465'},\n",
       "    {'type': 'mean', 'value': '10.52877589174219'},\n",
       "    {'type': 'stdev', 'value': '0.27672044568411663'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'studfac',\n",
       "   'labl': 'student-faculty ratio',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 150,\n",
       "     'min': '1.0099999904632568',\n",
       "     'max': '9.342857360839844'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '150'},\n",
       "    {'type': 'invd', 'value': '6'},\n",
       "    {'type': 'min', 'value': '1.0099999904632568'},\n",
       "    {'type': 'max', 'value': '9.342857360839844'},\n",
       "    {'type': 'mean', 'value': '3.7066598542531333'},\n",
       "    {'type': 'stdev', 'value': '1.3118621080628194'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'top10',\n",
       "   'labl': '=1 if ranked in top 10',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.0641025641025641'},\n",
       "    {'type': 'stdev', 'value': '0.24572439792441947'},\n",
       "    {'type': 'mean', 'wgtd': 'wgtd', 'value': 0.0724168303083735},\n",
       "    {'type': 'stdev', 'wgtd': 'wgtd', 'value': 0.25932231036778775}],\n",
       "   'var_catgry': [{'value': '0',\n",
       "     'stats': [{'type': 'freq', 'value': '146'},\n",
       "      {'type': 'freq', 'wgtd': 'wgtd', 'value': 826}]},\n",
       "    {'value': '1',\n",
       "     'stats': [{'type': 'freq', 'value': '10'},\n",
       "      {'type': 'freq', 'wgtd': 'wgtd', 'value': 64}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'r11_25',\n",
       "   'labl': '=1 if ranked 11-25',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.10256410256410256'},\n",
       "    {'type': 'stdev', 'value': '0.30436580663972007'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '140'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '16'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'r26_40',\n",
       "   'labl': '=1 if ranked 26-40',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.08333333333333333'},\n",
       "    {'type': 'stdev', 'value': '0.2772755316109005'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '143'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '13'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'r41_60',\n",
       "   'labl': '=1 if ranked 41-60',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 156,\n",
       "     'min': '0.0',\n",
       "     'max': '1.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '156'},\n",
       "    {'type': 'invd', 'value': '0'},\n",
       "    {'type': 'min', 'value': '0.0'},\n",
       "    {'type': 'max', 'value': '1.0'},\n",
       "    {'type': 'mean', 'value': '0.11538461538461539'},\n",
       "    {'type': 'stdev', 'value': '0.3205144747682703'}],\n",
       "   'var_catgry': [{'value': '0', 'stats': [{'type': 'freq', 'value': '138'}]},\n",
       "    {'value': '1', 'stats': [{'type': 'freq', 'value': '18'}]}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'llibvol',\n",
       "   'labl': 'log(libvol)',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 155,\n",
       "     'min': '4.820281505584717',\n",
       "     'max': '7.464509963989258'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '155'},\n",
       "    {'type': 'invd', 'value': '1'},\n",
       "    {'type': 'min', 'value': '4.820281505584717'},\n",
       "    {'type': 'max', 'value': '7.464509963989258'},\n",
       "    {'type': 'mean', 'value': '5.751980999977358'},\n",
       "    {'type': 'stdev', 'value': '0.4165479987301825'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'lcost',\n",
       "   'labl': 'log(cost)',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 150,\n",
       "     'min': '7.872074127197266',\n",
       "     'max': '9.929058074951172'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '150'},\n",
       "    {'type': 'invd', 'value': '6'},\n",
       "    {'type': 'min', 'value': '7.872074127197266'},\n",
       "    {'type': 'max', 'value': '9.929058074951172'},\n",
       "    {'type': 'mean', 'value': '9.39243366241455'},\n",
       "    {'type': 'stdev', 'value': '0.3689148449463717'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}}],\n",
       " 'weights': {'top10': {'wgt_freq': {0: 826, 1: 64},\n",
       "   'wgt_mean': 0.0724168303083735,\n",
       "   'wgt_stdev': 0.25932231036778775}}}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c0e3c986",
   "metadata": {},
   "outputs": [],
   "source": [
    "# read metadata and data from Stata file\n",
    "df,meta = pyreadstat.read_dta(fileinfo.file_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "0473b3e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'rank': 'law school ranking',\n",
       " 'salary': 'median starting salary',\n",
       " 'cost': 'law school cost',\n",
       " 'LSAT': 'median LSAT score',\n",
       " 'GPA': 'median college GPA',\n",
       " 'libvol': 'no. volumes in lib., 1000s',\n",
       " 'faculty': 'no. of faculty',\n",
       " 'age': 'age of law sch., years',\n",
       " 'clsize': 'size of entering class',\n",
       " 'north': '=1 if law sch in north',\n",
       " 'south': '=1 if law sch in south',\n",
       " 'east': '=1 if law sch in east',\n",
       " 'west': '=1 if law sch in west',\n",
       " 'lsalary': 'log(salary)',\n",
       " 'studfac': 'student-faculty ratio',\n",
       " 'top10': '=1 if ranked in top 10',\n",
       " 'r11_25': '=1 if ranked 11-25',\n",
       " 'r26_40': '=1 if ranked 26-40',\n",
       " 'r41_60': '=1 if ranked 41-60',\n",
       " 'llibvol': 'log(libvol)',\n",
       " 'lcost': 'log(cost)'}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# print metadata (column names, types, labels)\n",
    "meta.column_names_to_labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a6eec231",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['rank',\n",
       " 'salary',\n",
       " 'cost',\n",
       " 'LSAT',\n",
       " 'GPA',\n",
       " 'libvol',\n",
       " 'faculty',\n",
       " 'age',\n",
       " 'clsize',\n",
       " 'north',\n",
       " 'south',\n",
       " 'east',\n",
       " 'west',\n",
       " 'lsalary',\n",
       " 'studfac',\n",
       " 'top10',\n",
       " 'r11_25',\n",
       " 'r26_40',\n",
       " 'r41_60',\n",
       " 'llibvol',\n",
       " 'lcost']"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# column names\n",
    "meta.column_names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "737e1372",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'rank': '%9.0g',\n",
       " 'salary': '%9.0g',\n",
       " 'cost': '%9.0g',\n",
       " 'LSAT': '%9.0g',\n",
       " 'GPA': '%9.0g',\n",
       " 'libvol': '%9.0g',\n",
       " 'faculty': '%9.0g',\n",
       " 'age': '%9.0g',\n",
       " 'clsize': '%9.0g',\n",
       " 'north': '%9.0g',\n",
       " 'south': '%9.0g',\n",
       " 'east': '%9.0g',\n",
       " 'west': '%9.0g',\n",
       " 'lsalary': '%9.0g',\n",
       " 'studfac': '%9.0g',\n",
       " 'top10': '%9.0g',\n",
       " 'r11_25': '%9.0g',\n",
       " 'r26_40': '%9.0g',\n",
       " 'r41_60': '%9.0g',\n",
       " 'llibvol': '%9.0g',\n",
       " 'lcost': '%9.0g'}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# column data types info\n",
    "meta.original_variable_types"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "bcbdd99f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Pyreadstat offers many other metadata options, see https://github.com/Roche/pyreadstat?tab=readme-ov-file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "584163ee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rank</th>\n",
       "      <th>salary</th>\n",
       "      <th>cost</th>\n",
       "      <th>LSAT</th>\n",
       "      <th>GPA</th>\n",
       "      <th>libvol</th>\n",
       "      <th>faculty</th>\n",
       "      <th>age</th>\n",
       "      <th>clsize</th>\n",
       "      <th>north</th>\n",
       "      <th>...</th>\n",
       "      <th>east</th>\n",
       "      <th>west</th>\n",
       "      <th>lsalary</th>\n",
       "      <th>studfac</th>\n",
       "      <th>top10</th>\n",
       "      <th>r11_25</th>\n",
       "      <th>r26_40</th>\n",
       "      <th>r41_60</th>\n",
       "      <th>llibvol</th>\n",
       "      <th>lcost</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>128</td>\n",
       "      <td>31400.0</td>\n",
       "      <td>8340</td>\n",
       "      <td>155</td>\n",
       "      <td>3.15</td>\n",
       "      <td>216</td>\n",
       "      <td>45</td>\n",
       "      <td>12</td>\n",
       "      <td>210</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10.354563</td>\n",
       "      <td>4.666667</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>5.375278</td>\n",
       "      <td>9.028818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>104</td>\n",
       "      <td>33098.0</td>\n",
       "      <td>6980</td>\n",
       "      <td>160</td>\n",
       "      <td>3.50</td>\n",
       "      <td>256</td>\n",
       "      <td>44</td>\n",
       "      <td>113</td>\n",
       "      <td>190</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10.407228</td>\n",
       "      <td>4.318182</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>5.545177</td>\n",
       "      <td>8.850804</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>34</td>\n",
       "      <td>32870.0</td>\n",
       "      <td>16370</td>\n",
       "      <td>155</td>\n",
       "      <td>3.25</td>\n",
       "      <td>424</td>\n",
       "      <td>78</td>\n",
       "      <td>134</td>\n",
       "      <td>270</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>10.400315</td>\n",
       "      <td>3.461539</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>6.049734</td>\n",
       "      <td>9.703206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>49</td>\n",
       "      <td>35000.0</td>\n",
       "      <td>17566</td>\n",
       "      <td>157</td>\n",
       "      <td>3.20</td>\n",
       "      <td>329</td>\n",
       "      <td>136</td>\n",
       "      <td>89</td>\n",
       "      <td>277</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>10.463103</td>\n",
       "      <td>2.036765</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>5.796058</td>\n",
       "      <td>9.773721</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>95</td>\n",
       "      <td>33606.0</td>\n",
       "      <td>8350</td>\n",
       "      <td>162</td>\n",
       "      <td>3.38</td>\n",
       "      <td>332</td>\n",
       "      <td>56</td>\n",
       "      <td>70</td>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>10.422460</td>\n",
       "      <td>2.678571</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>5.805135</td>\n",
       "      <td>9.030017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>151</th>\n",
       "      <td>17</td>\n",
       "      <td>49321.0</td>\n",
       "      <td>13530</td>\n",
       "      <td>162</td>\n",
       "      <td>3.34</td>\n",
       "      <td>300</td>\n",
       "      <td>50</td>\n",
       "      <td>206</td>\n",
       "      <td>178</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>10.806106</td>\n",
       "      <td>3.560000</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>5.703783</td>\n",
       "      <td>9.512665</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>21</td>\n",
       "      <td>49900.0</td>\n",
       "      <td>11334</td>\n",
       "      <td>161</td>\n",
       "      <td>3.40</td>\n",
       "      <td>NaN</td>\n",
       "      <td>47</td>\n",
       "      <td>NaN</td>\n",
       "      <td>285</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10.817777</td>\n",
       "      <td>6.063830</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9.335563</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153</th>\n",
       "      <td>143</td>\n",
       "      <td>31500.0</td>\n",
       "      <td>7396</td>\n",
       "      <td>157</td>\n",
       "      <td>3.40</td>\n",
       "      <td>174</td>\n",
       "      <td>17</td>\n",
       "      <td>65</td>\n",
       "      <td>79</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>10.357743</td>\n",
       "      <td>4.647059</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>5.159055</td>\n",
       "      <td>8.908694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>154</th>\n",
       "      <td>3</td>\n",
       "      <td>69000.0</td>\n",
       "      <td>19780</td>\n",
       "      <td>171</td>\n",
       "      <td>3.82</td>\n",
       "      <td>850</td>\n",
       "      <td>100</td>\n",
       "      <td>140</td>\n",
       "      <td>101</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>11.141862</td>\n",
       "      <td>1.010000</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>6.745236</td>\n",
       "      <td>9.892426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>155</th>\n",
       "      <td>120</td>\n",
       "      <td>29800.0</td>\n",
       "      <td>12870</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>200</td>\n",
       "      <td>35</td>\n",
       "      <td>NaN</td>\n",
       "      <td>327</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>10.302263</td>\n",
       "      <td>9.342857</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>5.298317</td>\n",
       "      <td>9.462654</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>156 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     rank   salary   cost LSAT   GPA libvol faculty  age clsize  north  ...  \\\n",
       "0     128  31400.0   8340  155  3.15    216      45   12    210      1  ...   \n",
       "1     104  33098.0   6980  160  3.50    256      44  113    190      0  ...   \n",
       "2      34  32870.0  16370  155  3.25    424      78  134    270      0  ...   \n",
       "3      49  35000.0  17566  157  3.20    329     136   89    277      0  ...   \n",
       "4      95  33606.0   8350  162  3.38    332      56   70    150      0  ...   \n",
       "..    ...      ...    ...  ...   ...    ...     ...  ...    ...    ...  ...   \n",
       "151    17  49321.0  13530  162  3.34    300      50  206    178      0  ...   \n",
       "152    21  49900.0  11334  161  3.40    NaN      47  NaN    285      1  ...   \n",
       "153   143  31500.0   7396  157  3.40    174      17   65     79      0  ...   \n",
       "154     3  69000.0  19780  171  3.82    850     100  140    101      0  ...   \n",
       "155   120  29800.0  12870  NaN   NaN    200      35  NaN    327      1  ...   \n",
       "\n",
       "     east  west    lsalary   studfac  top10  r11_25  r26_40  r41_60   llibvol  \\\n",
       "0       0     0  10.354563  4.666667      0       0       0       0  5.375278   \n",
       "1       0     0  10.407228  4.318182      0       0       0       0  5.545177   \n",
       "2       1     0  10.400315  3.461539      0       0       1       0  6.049734   \n",
       "3       1     0  10.463103  2.036765      0       0       0       1  5.796058   \n",
       "4       0     1  10.422460  2.678571      0       0       0       0  5.805135   \n",
       "..    ...   ...        ...       ...    ...     ...     ...     ...       ...   \n",
       "151     1     0  10.806106  3.560000      0       1       0       0  5.703783   \n",
       "152     0     0  10.817777  6.063830      0       1       0       0       NaN   \n",
       "153     0     1  10.357743  4.647059      0       0       0       0  5.159055   \n",
       "154     1     0  11.141862  1.010000      1       0       0       0  6.745236   \n",
       "155     0     0  10.302263  9.342857      0       0       0       0  5.298317   \n",
       "\n",
       "        lcost  \n",
       "0    9.028818  \n",
       "1    8.850804  \n",
       "2    9.703206  \n",
       "3    9.773721  \n",
       "4    9.030017  \n",
       "..        ...  \n",
       "151  9.512665  \n",
       "152  9.335563  \n",
       "153  8.908694  \n",
       "154  9.892426  \n",
       "155  9.462654  \n",
       "\n",
       "[156 rows x 21 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# print data\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c850bac5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# export data to stata version 8\n",
    "#pyreadstat.pyreadstat.write_dta(df, \"/Downloads/export-stata-8.dta\", version=8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "4745718d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "rank         int64\n",
       "salary     float64\n",
       "cost        object\n",
       "LSAT        object\n",
       "GPA        float64\n",
       "libvol      object\n",
       "faculty     object\n",
       "age         object\n",
       "clsize      object\n",
       "north        int64\n",
       "south        int64\n",
       "east         int64\n",
       "west         int64\n",
       "lsalary    float64\n",
       "studfac    float64\n",
       "top10        int64\n",
       "r11_25       int64\n",
       "r26_40       int64\n",
       "r41_60       int64\n",
       "llibvol    float64\n",
       "lcost      float64\n",
       "dtype: object"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get df columns with type info\n",
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "bdd9d27d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 156 entries, 0 to 155\n",
      "Data columns (total 21 columns):\n",
      " #   Column   Non-Null Count  Dtype  \n",
      "---  ------   --------------  -----  \n",
      " 0   rank     156 non-null    int64  \n",
      " 1   salary   148 non-null    float64\n",
      " 2   cost     150 non-null    object \n",
      " 3   LSAT     150 non-null    object \n",
      " 4   GPA      149 non-null    float64\n",
      " 5   libvol   155 non-null    object \n",
      " 6   faculty  152 non-null    object \n",
      " 7   age      111 non-null    object \n",
      " 8   clsize   153 non-null    object \n",
      " 9   north    156 non-null    int64  \n",
      " 10  south    156 non-null    int64  \n",
      " 11  east     156 non-null    int64  \n",
      " 12  west     156 non-null    int64  \n",
      " 13  lsalary  148 non-null    float64\n",
      " 14  studfac  150 non-null    float64\n",
      " 15  top10    156 non-null    int64  \n",
      " 16  r11_25   156 non-null    int64  \n",
      " 17  r26_40   156 non-null    int64  \n",
      " 18  r41_60   156 non-null    int64  \n",
      " 19  llibvol  155 non-null    float64\n",
      " 20  lcost    150 non-null    float64\n",
      "dtypes: float64(6), int64(9), object(6)\n",
      "memory usage: 25.7+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "84741458",
   "metadata": {},
   "outputs": [],
   "source": [
    "# example for apply weights\n",
    "# uses WeightsColumn dict:\n",
    "# {\"field\": \"f1\", \"weight_field\": \"fld_weight\"}\n",
    "# where f1 is the field to be weighted and fld_weight is the field with the weights\n",
    "\n",
    "# var_names - list of variables to return\n",
    "\n",
    "# init params\n",
    "params_with_wgt= DictParams(file_path=filepath, var_names=[\"GPA\"], weights=[{\"weight_field\":\"lcost\", \"field\":\"GPA\"}])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "56c72be7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DictParams(file_path='/Volumes/webdev/editor/datafiles/editor/0c74b7f78409a4022a2c4c5a5ca3ee19/data/LAWSCH85.DTA', var_names=['GPA'], weights=[WeightsColumns(field='GPA', weight_field='lcost')], missings={}, dtypes={}, value_labels={}, name_labels={}, export_format='csv')"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "params_with_wgt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "20d7ae38",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "column name GPA\n",
      "column name lcost\n",
      "weights:  {'GPA': {'wgt_freq': {2: 9, 3: 9}, 'wgt_mean': 3.31224655102333, 'wgt_stdev': 0.19451495783479375}}\n"
     ]
    }
   ],
   "source": [
    "# get data with weights for a single variable - GPA\n",
    "variable_dict_wgt=datadict.get_data_dictionary_variable(params_with_wgt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "84b43a5f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'rows': 156,\n",
       " 'columns': 2,\n",
       " 'variables': [{'name': 'GPA',\n",
       "   'labl': 'median college GPA',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 149,\n",
       "     'min': '2.7300000190734863',\n",
       "     'max': '3.819999933242798'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '149'},\n",
       "    {'type': 'invd', 'value': '7'},\n",
       "    {'type': 'min', 'value': '2.7300000190734863'},\n",
       "    {'type': 'max', 'value': '3.819999933242798'},\n",
       "    {'type': 'mean', 'value': '3.302751677148294'},\n",
       "    {'type': 'stdev', 'value': '0.19977642750979446'},\n",
       "    {'type': 'mean', 'wgtd': 'wgtd', 'value': 3.31224655102333},\n",
       "    {'type': 'stdev', 'wgtd': 'wgtd', 'value': 0.19451495783479375}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}},\n",
       "  {'name': 'lcost',\n",
       "   'labl': 'log(cost)',\n",
       "   'var_intrvl': 'contin',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 150,\n",
       "     'min': '7.872074127197266',\n",
       "     'max': '9.929058074951172'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '150'},\n",
       "    {'type': 'invd', 'value': '6'},\n",
       "    {'type': 'min', 'value': '7.872074127197266'},\n",
       "    {'type': 'max', 'value': '9.929058074951172'},\n",
       "    {'type': 'mean', 'value': '9.39243366241455'},\n",
       "    {'type': 'stdev', 'value': '0.3689148449463717'}],\n",
       "   'var_catgry': [],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}}],\n",
       " 'weights': {'GPA': {'wgt_freq': {2: 9, 3: 9},\n",
       "   'wgt_mean': 3.31224655102333,\n",
       "   'wgt_stdev': 0.19451495783479375}}}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "variable_dict_wgt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "6115c6ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DictParams(file_path='/Volumes/webdev/editor/datafiles/editor/0c74b7f78409a4022a2c4c5a5ca3ee19/data/LAWSCH85.DTA', var_names=['age'], weights=[], missings={'age': [206]}, dtypes={}, value_labels={}, name_labels={}, export_format='csv')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# example for setting user defined missings\n",
    "#dictparams2= DictParams(file_path=filepath, \n",
    "#                        weights=[{\"weight_field\":\"a1\", \"field\":\"a2\"}], \n",
    "#                        missings=[{\"field\":\"a1\",\"missings\":[1,\"2\"]}])\n",
    "\n",
    "missing_params={        \n",
    "        \"age\":[206]\n",
    "    }\n",
    "\n",
    "\n",
    "# set age=206 as missing\n",
    "params_with_missing= DictParams(file_path=filepath, var_names=[\"age\"], missings=missing_params)\n",
    "params_with_missing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ee7250a8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'rows': 156,\n",
       " 'columns': 1,\n",
       " 'variables': [{'name': 'age',\n",
       "   'labl': 'age of law sch., years',\n",
       "   'var_intrvl': 'discrete',\n",
       "   'loc_width': 9,\n",
       "   'var_valrng': {'range': {'UNITS': 'REAL',\n",
       "     'count': 111,\n",
       "     'min': '3.0',\n",
       "     'max': '206.0'}},\n",
       "   'var_sumstat': [{'type': 'vald', 'value': '110'},\n",
       "    {'type': 'invd', 'value': '46'},\n",
       "    {'type': 'min', 'value': '3.0'},\n",
       "    {'type': 'max', 'value': '196.0'},\n",
       "    {'type': 'mean', 'value': '84.72727272727273'},\n",
       "    {'type': 'stdev', 'value': '39.41775995453311'}],\n",
       "   'var_catgry': [{'value': '3', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '6', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '9', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '10', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '12', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '13', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '20', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '23', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '24', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '26', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '29', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '31', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '32', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '34', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '38', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '56', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '58', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '59', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '60', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '61', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '62', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '65', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '70', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '71', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '72', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '73', 'stats': [{'type': 'freq', 'value': '4'}]},\n",
       "    {'value': '74', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '76', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '77', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '78', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '79', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '82', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '84', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '85', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '86', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '89', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '90', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '91', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '92', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '93', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '94', 'stats': [{'type': 'freq', 'value': '5'}]},\n",
       "    {'value': '95', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '97', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '100', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '101', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '102', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '107', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '112', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '113', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '115', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '116', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '118', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '120', 'stats': [{'type': 'freq', 'value': '3'}]},\n",
       "    {'value': '126', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '128', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '131', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '133', 'stats': [{'type': 'freq', 'value': '2'}]},\n",
       "    {'value': '134', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '136', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '139', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '140', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '144', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '149', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '150', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '151', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '152', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '160', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '173', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '196', 'stats': [{'type': 'freq', 'value': '1'}]},\n",
       "    {'value': '206',\n",
       "     'stats': [{'type': 'freq', 'value': '1'}],\n",
       "     'is_missing': 1}],\n",
       "   'var_catgry_labels': [],\n",
       "   'var_format': {'type': 'numeric', 'schema': 'other'}}],\n",
       " 'weights': {}}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result_miss=datadict.get_data_dictionary_variable(params_with_missing)\n",
    "result_miss"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
