# Iterating on regressions using GLM

**URL:** <https://discourse.julialang.org/t/iterating-on-regressions-using-glm/6686>\
**Category:** General Usage\
**Tags:** question, glm\
**Created:** [October 25, 2017, 7:52pm UTC](https://discourse.julialang.org/t/iterating-on-regressions-using-glm/6686 "2017-10-25T19:52:19Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![mathtd](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mathtd](https://discourse.julialang.org/u/mathtd)\
**Post date:** [October 25, 2017, 9:52pm UTC](https://discourse.julialang.org/t/iterating-on-regressions-using-glm/6686/3 "2017-10-25T21:52:32Z")

</div>

Ok this was helpful but I’m very confused by the whole thing. If I run

```julia
data = DataFrame(x=[2,3],y=[3,6])
r = :x
@eval temp=glm(@formula(y ~ $r), data, Normal(), IdentityLink())

```

everything works, no problem. However, the following throws an error

```julia
function foo()
       data2 = DataFrame(x=[2,3],y=[3,6])
       r2 = :x
       @eval temp=glm(@formula(y ~ $r2), data2, Normal(), IdentityLink())
end
foo()

```

The outcome is

```julia
ERROR: UndefVarError: data2 not defined

```

What’s going on?

---

_[View the full topic](https://discourse.julialang.org/t/iterating-on-regressions-using-glm/6686)._
