BUG: Fix GSO values when writing latin-1 strLs
State: closed

The size calculation of the string is incorrect when writing characters
that have a different encoding in latin-1 and utf-8. The utf-8 size
needs to be written instead of the latin-1 size.

- [x] closes #23573
- [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:
Hello @bashtage! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/io/stata.py`](https://github.com/bashtage/pandas/blob/2b5dc0a12562bf322d81d7d4ffa02268c8273653/pandas/io/stata.py) !

 - There are no PEP8 issues in the file [`pandas/tests/io/test_stata.py`](https://github.com/bashtage/pandas/blob/2b5dc0a12562bf322d81d7d4ffa02268c8273653/pandas/tests/io/test_stata.py) !


lgtm. ping on green.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24337?src=pr&el=h1) Report
> Merging [#24337](https://codecov.io/gh/pandas-dev/pandas/pull/24337?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/6c8aabc0a076fd3597a708f81b4aad192b19822b?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

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

```diff
@@           Coverage Diff           @@
##           master   #24337   +/-   ##
=======================================
  Coverage   92.28%   92.28%           
=======================================
  Files         162      162           
  Lines       51833    51833           
=======================================
  Hits        47833    47833           
  Misses       4000     4000
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.68% <ø> (ø)` | :arrow_up: |
| #single | `42.99% <ø> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24337?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/24337/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `93.06% <0%> (-0.04%)` | :arrow_down: |
| [pandas/core/reshape/tile.py](https://codecov.io/gh/pandas-dev/pandas/pull/24337/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS90aWxlLnB5) | `94.82% <0%> (+0.06%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24337?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/24337?src=pr&el=footer). Last update [6c8aabc...280f48b](https://codecov.io/gh/pandas-dev/pandas/pull/24337?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/24337?src=pr&el=h1) Report
> Merging [#24337](https://codecov.io/gh/pandas-dev/pandas/pull/24337?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/6c8aabc0a076fd3597a708f81b4aad192b19822b?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

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

```diff
@@           Coverage Diff           @@
##           master   #24337   +/-   ##
=======================================
  Coverage   92.28%   92.28%           
=======================================
  Files         162      162           
  Lines       51833    51833           
=======================================
  Hits        47833    47833           
  Misses       4000     4000
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.68% <ø> (ø)` | :arrow_up: |
| #single | `42.99% <ø> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24337?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/24337/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `93.06% <0%> (-0.04%)` | :arrow_down: |
| [pandas/core/reshape/tile.py](https://codecov.io/gh/pandas-dev/pandas/pull/24337/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS90aWxlLnB5) | `94.82% <0%> (+0.06%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24337?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/24337?src=pr&el=footer). Last update [6c8aabc...280f48b](https://codecov.io/gh/pandas-dev/pandas/pull/24337?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

thanks @bashtage