<p>If you want to draw a budget constrain which takes $m$, $p_1$ and $p_2$ as inputs, this is a R code that does it:</p>

<pre><code># Clear environment
remove(list = ls())

# Enter inputs
m=100
p1=1
p2=2

# Create plot
plot(c(0,(m/p1)*1.1), c(0,(m/p2)*1.1), type = "n", xlab = expression(x[1]), ylab = expression(x[2]), xaxs="i", yaxs="i")
abline(m/p2, -p1/p2, col = 1, lwd = 2)
</code></pre>

<p>You get:</p>

<p><a href="https://i.sstatic.net/9NTH0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9NTH0.png" alt="enter image description here"></a></p>

<p>The limit of axes adjust accordingly to the parameters, adding a 10% more to each axis crossing point.</p>

CC BY-SA 3.0
2017-04-28T16:29:07.370Z
2017-04-28T16:29:07.370Z
luchonacho
<p>Another R code that does it...</p>

<pre><code>m &lt;- 100
p &lt;- c(1, 2) 
curve(m/p[2] - p[1]/p[2]*x, from = 0, to = m/p[1], lwd = 2,
      xlab = expression(x[1]),
      ylab = expression(x[2]))
</code></pre>

<p><a href="https://i.sstatic.net/eQ6K3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eQ6K3.png" alt="enter image description here"></a></p>

CC BY-SA 3.0
2017-04-28T18:50:51.770Z
2017-04-28T19:16:50.260Z
2017-04-28T19:16:50.260Z
snoram
<p>Im interested in programming a budget line or PPF which is responsive to changes in relative prices, and income effect.</p>

<p>I know the equation for the budget line is $$m\geq p_1x_1+p_2x_2$$
Lets say we have an Income of $m=100$ and prices $p_1=1$ and $p_2=2$.</p>

<p>How would I go about programming this into an excel spreadsheet or R?</p>

CC BY-SA 3.0
2017-04-28T09:58:26.310Z
Can you provide more details about the production theory you are thinking of? Is this an abstract theory, using $n$ inputs $x_i$, or is this about capital and labour? Which production function? Also, have you done something? I'm not sure asking for code is entirely on-topic.
luchonacho
CC BY-SA 3.0
2017-04-28T13:36:29.193Z
Agreed. All you've said is: "I want to program something about producer theory". That's absurdly general.
TheSaint321
CC BY-SA 3.0
2017-04-28T16:11:57.757Z
@luchonacho better?
EconJohn
CC BY-SA 3.0
2017-04-28T16:16:26.967Z
I would say so. But, in the end, all what you have is a function. You still have two unknowns and one equation. The system is undetermined. Do you want simply to create a graph of this, which moves according to your chosen parameterisation? If you could add more info to the question, it would be great. At the moment I don't think it's clear enough.
luchonacho
CC BY-SA 3.0
2017-04-28T16:38:51.330Z
Yeah, I just want a graph which changes  by parameterisation. Im kinda just going back to basics as i want to apply my economic theory to real data sets. this is a start.
EconJohn
CC BY-SA 3.0
2017-04-28T16:52:50.903Z
There is a book called "Microeconomics using Excel". You might find that useful. That is if you wish to do similar exercises.
Toby
<microeconomics><software>
How to create a Budget line in excel or R
EconJohn
# How to create a Budget line in excel or R

(Asked by: username_0 on 2017-04-27)

Im interested in programming a budget line or PPF which is responsive to changes in relative prices, and income effect.

I know the equation for the budget line is $$m\geq p\_1x\_1+p\_2x\_2$$
Lets say we have an Income of $m=100$ and prices $p\_1=1$ and $p\_2=2$.

How would I go about programming this into an excel spreadsheet or R?

**Tags:** microeconomics, software

> **Comments:**
> **username_1**: Can you provide more details about the production theory you are thinking of? Is this an abstract theory, using $n$ inputs $x_i$, or is this about capital and labour? Which production function? Also, have you done something? I'm not sure asking for code is entirely on-topic.  
> **username_2**: Agreed. All you've said is: "I want to program something about producer theory". That's absurdly general.  
> **username_0**: @username_1 better?  
> **username_1**: I would say so. But, in the end, all what you have is a function. You still have two unknowns and one equation. The system is undetermined. Do you want simply to create a graph of this, which moves according to your chosen parameterisation? If you could add more info to the question, it would be great. At the moment I don't think it's clear enough.  
> **username_0**: Yeah, I just want a graph which changes  by parameterisation. Im kinda just going back to basics as i want to apply my economic theory to real data sets. this is a start.  
> **username_3**: There is a book called "Microeconomics using Excel". You might find that useful. That is if you wish to do similar exercises.  

---

## 2 answers

### Answer by username_4 on 2017-04-28. Score: 4 | Accepted answer

Another R code that does it...

```
m <- 100
p <- c(1, 2) 
curve(m/p[2] - p[1]/p[2]*x, from = 0, to = m/p[1], lwd = 2,
      xlab = expression(x[1]),
      ylab = expression(x[2]))

```

[![enter image description here](https://i.sstatic.net/eQ6K3.png)](https://i.sstatic.net/eQ6K3.png)


---

### Answer by username_1 on 2017-04-28. Score: 3

If you want to draw a budget constrain which takes $m$, $p\_1$ and $p\_2$ as inputs, this is a R code that does it:

```
# Clear environment
remove(list = ls())

# Enter inputs
m=100
p1=1
p2=2

# Create plot
plot(c(0,(m/p1)*1.1), c(0,(m/p2)*1.1), type = "n", xlab = expression(x[1]), ylab = expression(x[2]), xaxs="i", yaxs="i")
abline(m/p2, -p1/p2, col = 1, lwd = 2)

```

You get:

[![enter image description here](https://i.sstatic.net/9NTH0.png)](https://i.sstatic.net/9NTH0.png)

The limit of axes adjust accordingly to the parameters, adding a 10% more to each axis crossing point.


---

