Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dfmerge updated #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
8 changes: 4 additions & 4 deletions src/DataFrame_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -566,15 +566,15 @@ function dfmerge(df1::DataFrame,df2::DataFrame,linkers::Union{Symbol,Vector};kin
error("`:_merge' exists in the second dataframe")
end

df1[:___mergeleft___] = ones(Int8,size(df1,1))
df2[:___mergeright___] = ones(Int8,size(df2,1))
df1[!,:___mergeleft___] = ones(Int8,size(df1,1))
df2[!,:___mergeright___] = ones(Int8,size(df2,1))

df_merged = join(df1,df2,on = linkers,kind=kind)
df_merged[:_merge] = zeros(Int8,size(df_merged,1))
df_merged[!,:_merge] = zeros(Int8,size(df_merged,1))
for i = 1:size(df_merged,1)
if isna(df_merged[i,:___mergeright___])
df_merged[i,:_merge] = 1
elseif isna(df_merged[i,:___mergeleft___])
elseif ismissing(df_merged[i,:___mergeleft___])
df_merged[i,:_merge] = 2
elseif df_merged[i,:___mergeleft___] == 1 && df_merged[i,:___mergeright___] == 1
df_merged[i,:_merge] = 3
Expand Down
7 changes: 6 additions & 1 deletion src/Stata_Reader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function read_stata!(fn,df::DataFrame,label::Dict; categorize=true, verbose=fals
println("Processing variable ",j," ", varlist[j])
end

df[varlist[j]] = alloc_array(typelist[j],fmtlist[j],nobs)
df[!,varlist[j]] = alloc_array(typelist[j],fmtlist[j],nobs)

for i in 1:nobs

Expand Down Expand Up @@ -368,6 +368,11 @@ function read_stata!(fn,df::DataFrame,label::Dict; categorize=true, verbose=fals
categorical!(df,varlist[j])
gc()
end

# if there are no missing values, convert the variable to an appropriate vector
if sum(ismissing.(df[:,j])) == 0
df[!,varlist[j]] = convert(Vector{nonmissingtype(eltype(df[!,varlist[j]]))},df[!,varlist[j]])
end
end

# read value labels
Expand Down