BUG: Set index when reading stata file
State: closed

Ensures index is set when requested when reading state dta file

closes #16342

- [x] closes #16342
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Bug
name: IO Stata
description: read_stata, to_stata

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=h1) Report
> Merging [#17328](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/96f92eb1c696723b6465fdc273dc8406201c606a?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/17328/graphs/tree.svg?width=650&height=150&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17328      +/-   ##
==========================================
+ Coverage   91.01%   91.02%   +<.01%     
==========================================
  Files         162      162              
  Lines       49567    49571       +4     
==========================================
+ Hits        45113    45120       +7     
+ Misses       4454     4451       -3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.8% <100%> (+0.02%)` | :arrow_up: |
| #single | `40.24% <0%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/stata.py](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree#diff-cGFuZGFzL2lvL3N0YXRhLnB5) | `93.69% <100%> (+0.02%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.72% <0%> (-0.1%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `65.05% <0%> (+1.81%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=footer). Last update [96f92eb...b8e36ac](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=h1) Report
> Merging [#17328](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/96f92eb1c696723b6465fdc273dc8406201c606a?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/17328/graphs/tree.svg?height=150&width=650&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17328      +/-   ##
==========================================
+ Coverage   91.01%   91.02%   +<.01%     
==========================================
  Files         162      162              
  Lines       49567    49571       +4     
==========================================
+ Hits        45113    45120       +7     
+ Misses       4454     4451       -3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.8% <100%> (+0.02%)` | :arrow_up: |
| #single | `40.24% <0%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/stata.py](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree#diff-cGFuZGFzL2lvL3N0YXRhLnB5) | `93.69% <100%> (+0.02%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.72% <0%> (-0.1%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `65.05% <0%> (+1.81%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=footer). Last update [96f92eb...b8e36ac](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=h1) Report
> Merging [#17328](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/0d676a3ccf1d7aa986416a7488b941496f936d98?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `95.83%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/17328/graphs/tree.svg?height=150&width=650&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #17328      +/-   ##
==========================================
- Coverage   91.01%   90.99%   -0.02%     
==========================================
  Files         163      163              
  Lines       49567    49575       +8     
==========================================
- Hits        45113    45112       -1     
- Misses       4454     4463       +9
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.78% <95.83%> (ø)` | :arrow_up: |
| #single | `40.26% <62.5%> (-0.06%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/stata.py](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree#diff-cGFuZGFzL2lvL3N0YXRhLnB5) | `93.71% <95.83%> (+0.04%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.72% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=footer). Last update [0d676a3...4e30df8](https://codecov.io/gh/pandas-dev/pandas/pull/17328?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Did we want to change the keyword from `index` to `index_col` to match `read_csv`?
Probably a good idea.

Does this need deprecation?
Last one, is there a pattern to follow for renaming (e.g. a decorator, *kwargs, etc)
Yeah, there's an `@deprecate_kwarg` decorator somewhere. Honestly not sure about whether it needs a deprecation, since the old one didn't do anything, but we may as well.
It's in `pandas/util/_decorators.py` btw.
I went ahead and did the insta-deprecate.
> minor comments. can you deprecate index (and direct to index_col) as well.

Do we need a deprecation, or can we just "break" API here. `index=...` didn't work at all earlier, so I'm OK with just changing without a deprecation cycle.

Ahh I see https://github.com/pandas-dev/pandas/pull/17328/commits/4e30df8b68d78b6fba67c8145b032f7b0e6a03dd now so nevermind, that's fine.
@jreback @TomAugspurger I think this is GTG
Thanks!