why use dummies and not different integers for categorical data? I am new to stats and I want to use a regression to determine income
See below table example




age
class
location
income




23
Adult
London
23000


44
Adult
Glasgow
45000


75
Senior
Birmingham
37000


12
Child
Coventry
300




I know the different stats packages (python, r) create something like this when they have to deal with categorical data :




age
Adult
Senior
Child




23
1
0
0


44
1
0
0


75
0
1
0


12
0
0
1




Why can't we use something like this instead when we're doing a regression ?




age
class
location




23
1
1


44
1
2


75
2
3


12
3
4




The reason I am asking is because location has a lot of different values and those are converted to like 30 something columns

With a categorical variable you often want to estimate a different value for each category.
For example:
$$\text{estimate} = \beta_{adult} \cdot x_{adult} + \beta_{senior} \cdot x_{senior} + \beta_{child} \cdot x_{child} $$
which you can also read as
$$\text{estimate} = \begin{cases}
\beta_{adult} & \quad \text{if } x_{adult} = 1, x_{senior}=0, x_{child} =0\\
\beta_{senior} & \quad  \text{if } x_{adult} = 0, x_{senior}=1, x_{child} =0\\
\beta_{child} & \quad\text{if } x_{adult} = 0, x_{senior}=0, x_{child} =1\\
\end{cases}$$

Your suggestion would treat the categorical variable as a numerical variable which only allows to estimate a single value and makes that the estimated for the different groups are dependent
$$\text{estimate} = \beta_{class} \cdot x_{class} $$
which is like
$$\text{estimate} = \begin{cases}
1\cdot \beta_{class} & \quad \text{if } x_{class} = 1 \\
2\cdot \beta_{class} & \quad \text{if } x_{class} = 2 \\
3\cdot \beta_{class} & \quad \text{if } x_{class} = 3 \\
\end{cases}$$


The reason I am asking is because location has a lot of different values and those are converted to like 30 something columns

The reason for the dummy variables and those many additional columns is because in the underlying algebra that estimates the 30 parameters you need a column for each parameter that you estimate. The linear formula multiplies each parameter with a column. If you predict more parameters (like for a categorical parameter) then you need to convert each category into their own column.
