# Converting to DataFrame

**URL:** https://discourse.julialang.org/t/converting-to-dataframe/44828
**Category:** Data
**Tags:** dataframes
**Created:** [August 12, 2020, 9:45pm UTC](https://discourse.julialang.org/t/converting-to-dataframe/44828 "2020-08-12T21:45:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![danicaratelli](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@danicaratelli](https://discourse.julialang.org/u/danicaratelli)
#### Post date: [August 12, 2020, 9:45pm UTC](https://discourse.julialang.org/t/converting-to-dataframe/44828/1 "2020-08-12T21:45:06Z")

</div>

I am loading a large .dta file and then converting it to a DataFrame. However, because of its size, the conversion takes a very long time (~20mins). I don’t need all of the columns in the file so I am wondering whether anyone knows of a way to convert only a subset of it.

Specifically:

```julia
using DataFrames, StatFiles

df_1 = load("data.dta");
df_2 = DataFrame(df_1);
df_3 = df_2[!,:col1];

```

step 2 takes a long time so if there were a way to invert steps 3 and 2, namely first select the columns I want and then convert to DataFrame, that would speed things up a lot. Any help would be greatly appreciated.

Thanks!

---

<div class="post-metadata">

### Author: ![anon37204545](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon37204545](https://discourse.julialang.org/u/anon37204545)
#### Post date: [August 12, 2020, 10:59pm UTC](https://discourse.julialang.org/t/converting-to-dataframe/44828/2 "2020-08-12T22:59:36Z")

</div>

I think you can [convert .dta to .csv](https://stackoverflow.com/questions/2536047/convert-a-dta-file-to-csv-without-stata-software) first, manipulate CSV (e.g. with [CSV.jl](https://juliadata.github.io/CSV.jl/stable)) and then convert that to a `DataFrame`.

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [August 13, 2020, 1:08am UTC](https://discourse.julialang.org/t/converting-to-dataframe/44828/3 "2020-08-13T01:08:23Z")

</div>

I don’t think there is a way to load a subset of the columns.

I agree that you should save the data as .csv. If you have access to stata thats very easy. Otherwise both R and pandas have `.dta`. However I’m not confident they are any better than Julia’s, since I think StatFiles uses the same underlying library as they do.

---

<div class="post-metadata">

### Author: ![danicaratelli](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@danicaratelli](https://discourse.julialang.org/u/danicaratelli)
#### Post date: [August 13, 2020, 1:45am UTC](https://discourse.julialang.org/t/converting-to-dataframe/44828/4 "2020-08-13T01:45:15Z")

</div>

Thank you both. I ended up calling Julia via RCall. That seems to work much faster than loading the .dta file directly via Julia.

Thanks!

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [August 13, 2020, 10:55am UTC](https://discourse.julialang.org/t/converting-to-dataframe/44828/5 "2020-08-13T10:55:17Z")

</div>

It’s weird that it takes much longer than R. @davidanthoff probably knows.
