{"record":{"id":"19c51266cd9611d2","repo":"OpenBB-finance/OpenBB","slug":"this-analysis-requires-at-least-3-items-in-the-dat","errorCode":null,"errorMessage":"This analysis requires at least 3 items in the dataset.","messagePattern":"This analysis requires at least 3 items in the dataset\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/econometrics/openbb_econometrics/econometrics_router.py","lineNumber":696,"sourceCode":"        list of columns to use as exogenous variables.\n\n    Returns\n    -------\n    OBBject[dict]\n        OBBject with the fit model returned\n    \"\"\"\n    # pylint: disable=import-outside-toplevel\n    import statsmodels.api as sm\n    from linearmodels.panel import RandomEffects\n    from openbb_core.app.utils import (\n        basemodel_to_df,\n        get_target_column,\n        get_target_columns,\n    )\n\n    X = get_target_columns(basemodel_to_df(data), x_columns)\n    if len(X) < 3:\n        raise ValueError(\"This analysis requires at least 3 items in the dataset.\")\n    y = get_target_column(basemodel_to_df(data), y_column)\n    exogenous = sm.add_constant(X)\n    results = RandomEffects(y, exogenous).fit()\n    return OBBject(results={\"results\": results})\n\n\n@router.command(\n    methods=[\"POST\"],\n    examples=[\n        APIEx(\n            parameters={\n                \"y_column\": \"portfolio_value\",\n                \"x_columns\": [\"risk_free_rate\"],\n                \"data\": APIEx.mock_data(\"panel\"),\n            }\n        ),\n    ],\n)","sourceCodeStart":678,"sourceCodeEnd":714,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/econometrics/openbb_econometrics/econometrics_router.py#L678-L714","documentation":"Raised by the panel random-effects regression endpoint in openbb_econometrics when the exogenous (X) frame has fewer than 3 rows. linearmodels' RandomEffects estimator cannot identify variance components with under 3 observations, so the router pre-empts it with this explicit ValueError instead of an opaque statsmodels/linearmodels failure.","triggerScenarios":"Calling obb.econometrics.panel(..., model='random') (the RandomEffects command around line 696) with a dataset of 0-2 rows; passing an empty results list from a provider; slicing a DataFrame down to 2 observations before fitting.","commonSituations":"Provider responses limited by date range or symbols returning only 1-2 records, filters (dropna, date windows) accidentally shrinking the panel, or unit-testing the endpoint with toy data of 2 rows.","solutions":["Inspect len(data) / data.to_df().shape — the X frame must have >= 3 rows.","Widen the query: more date range, more entities, or fewer dropna filters so more rows survive.","If the sample is genuinely tiny, use a simpler model (plain OLS via obb.econometrics.ols) that works with fewer observations."],"exampleFix":"# before\nres = obb.econometrics.panel_re(data=df_2rows, y_column='y', x_columns=['x1'])  # only 2 rows\n\n# after\ndf = df.dropna(subset=['y', 'x1'])\nassert len(df) >= 3, f'need >=3 rows, got {len(df)}'\nres = obb.econometrics.panel_re(data=df, y_column='y', x_columns=['x1'])","handlingStrategy":"validation","validationCode":"df = data.to_df().dropna(subset=[y_column] + list(x_columns))\nassert len(df) >= 3, f'random effects needs >= 3 rows, got {len(df)}'","typeGuard":"def sufficient_rows(df, minimum: int = 3) -> bool:\n    \"\"\"True when the frame has at least `minimum` usable rows.\"\"\"\n    return len(df) >= minimum","tryCatchPattern":"try:\n    res = obb.econometrics.panel_re(data, y_column=y, x_columns=xs)\nexcept ValueError as e:\n    if 'at least 3 items' in str(e):\n        raise SystemExit('expand the sample: more dates or entities') from e\n    raise","preventionTips":["Count rows after dropna before choosing a panel model.","Prefer OLS for samples smaller than 3 observations.","Widen provider date ranges in automated pipelines and assert minimum row counts."],"tags":["econometrics","panel","random-effects","insufficient-data"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}